Why do we use if statements in Javascript?
To do something only if a condition is true.
// There are many color constants. You can set an objects color like
obj.setColor(color);
Example: call moveBall every 40 Milliseconds
function moveBall() {ball.move(x, y);}
How many times should start function be defined?
1
In the first game, players had to adhere to a strict "stop" condition. Which coding concept best resembles this, where a certain condition must be met before proceeding?
conditional statements (like if/else)
Why do we use if/else statements?
To either do something if a condition is true or do something else.
Assign to an existing variable
myVarName = 10
//This moves Karel to a wall/
var height = getheight(); while(frontisclear()){move();}
Why do we use functions in coding?
Break down program into smaller parts, avoid repeating code and make program more readable.
The Dalgona candy challenge presented players with a complex shape to carve. In coding, how would you represent this complex shape, perhaps using a 2D array?
Data structures (like arrays or matrices) to represent the shape's coordinates and patterns.
What must be true before the function is called?
what is precondition
What does the following mean: for(var i = 0; i < 10; i ++){putball();
/ This puts down 10 balls /
What does this mean: for (ar i = 0; i , 10; i++) {move();}
loop move 10 times
A way to define a new command in a program
Function
The Glass Bridge game involved a 50/50 chance of stepping on safe or breaking glass. How could you simulate this random outcome in a coding program?
Random number generation or probability functions.
Let us do one thing if a condition is true, and something else otherwise
If/else statement
What does the term mean: txt.move(dx, dy)
Var color = new color(255, 24, 180);
for(var i = 0; i <arr.length; i++){var cur = arr[i];
looping over an array
What is a function?
A way to define a new command in a program
The Tug-of-war game required players to work together strategically. In a multi-agent system, how would you model the cooperation and competition dynamics between the players?
Game theory, multi-agent systems, or distributed algorithms.
Why do we use // to write in the code
to make it clear of what is going on in the code
The values are between 0-255 for each component.
car color = new Color(128, 128, 128);
Allows you to repeat a section of code a fixed number of times
For loop
A way to break down a program into smaller, more manageable parts
function!
What is the name of the game where players must form teams to play tug-of-war on a moving platform?
Tug-of-war