How do you make a comment?
by putting // in the beginning
ex:
//this is a comment
How do you make a variable?
you put var in the front of your statement.
How do you make a loop that goes on forever?
you start with the word while.
how do you make the hero move right?
hero.moveRight();
Why do we use comments?
So that we/other people looking at our code understands what it does
What do variables do?
They store information so that you can use later on.
what do while loops do?
basically they go on until the condition you put inside of it is false. basically looks like...
ex: the condition is age < 10. while loops go on until age is no longer < 10.
var age = 0;
while(age < 10){
age+=1;
}
console.log(age);
// should print out 10
how do you make the hero attack Greg?
hero.attack("Greg");
Which of the following are comments?
a) if(age > 10){eat food}
b)//this code is for moving the hero character up
c) this code is for moving the hero down
Which one is a variable?
a) //var v = 0;
b) var v = "hello";
c) if(time > 0){console.log('hello')}
b. because it starts with var. a would be a variable if it didnt have // in front but with // its not a comment.
Which one is a loop?
a) while(true){console.log("hi")}
b) if(true){console.log("hey")}
c) //loop
a is a loop.
Make the hero attack the nearest Enemy.
hero.attack(enemy);
There are 2 different ways to write comments. // is for single line comments and we have another way to write multi line comments. How do you do that?
ex: fill in the __.
// comment1
//comment2
__comment1
comment2__
/* to be in front of comment 1 and */ to be after comment 2
Create your own variable and set it equal to whatever you want
3 parts to a variable.
1) var in the beginning
2) create a unique name
3) set it equal to something (optional)
Ex: var cookie = 1;
Create your own while loop.
ex: while(true){
console.log("hi")
}
Make the hero move up, left, down, right indefinitely.
while(true){
hero.moveUp();
hero.moveLeft();
hero.moveDown();
hero.moveRight();
}
What is the difference between // and /**/
// is for single line commenting
/**/ is for multiline commenting
Create a variable called cookie and set it equal to 0.
var cookie = 0;
create a while loop that will make the hero move left then right indefinitely.
hero.moveLeft();
hero.moveRight();
}Create a variable called steps and set it equal to 1.
Then create a while loop that goes on forever and will make the hero walk up steps amount of time.
var steps = 1;
while(true){
hero.moveUp(steps)
}