Professor Kate Poirier, Spring 2017

Author: David Kirsch

In-class Exercise algorithm in JavaScript

I know two other students wrote an algorithm in Java and C++, but I had finished my code right after class the other day and forgot to post on here. Incase others wanted to see another way to solve it, I used JavaScript.

background(255, 255, 255);
var m = 30;
var i = 0;
var x = 7;
var a = 19;
var c = 8;
var num, div, num1, mod;

while( i <10){
var change = (i+1) * 25;
num = (a*x)+c;
div = floor(num/ m);
num1 = div*30;
fill(0, 0, 0);
text(x, 100,change);
x= num-num1;
i++;
}

In the above code, I declared/ initialized some variables. I used a While loop using "i" as a counter. I have the variables outside the loop as a static number and "change", "num", "div", "num1", "x" as a variable inside the loop that will continuously change each time the program loops.

I hope this helps if anyone was confused, or wanted to see another solution. Feel free to message/ reply to this post if you have questions.

I attached a screenshot I took. I wrote the code in Khan Academy since the website lets you write programs and run them.

Also, the variable “change” is just used to format where I want the text to print the number. You can see that in the text command where I text “x” and then place it at 100 on the X-axis and the “change” is the Y-axis. The X- axis is always at 100 and the “change” keeps changing on the Y-axis by 25 pixels each loop.

Introducing David Kirsch

 


Hello!

My name is David Kirsch and my major is Computer Systems Technology. Before returning back to college, I was a performer. I graduated from a NYC conservatory in 2007 and performed around the country for 7 years. After making the decision to change careers, I figured I would go into a career that I was surrounded with my entire childhood, COMPUTERS! My father was a software developer, so I had read some of the books he would bring home. It was always interesting to me.

After I graduate from CityTech, I would like to get a job as a software developer, eventually working my way up to a Database Administrator. I would like to find a job that I could work overseas for a few years or part of the year.

During the course of this class, I would like to get a better understanding of algorithms and how they were built to overcome problems.

Although I changed careers, I still love taking dance classes, especially Tap. I enjoy going to the beach (in the summer) and traveling around the world too.