Coffee School If statements

Code Editor

// don't change these! var numbers = [4, 34, 23, 7, 34, -10]; for (var number in numbers) { // for each number, do this: // Remember, access the current number with "numbers[number]". // Then write "true" or "false" to the console if it is greater than 10. }

Preview

Console Log:

If statements

Time to complete: 5 minutes

##Goal: Comparing values

You will want to change what your program does depending on the inputs. In javascript, === is used to test if two values are equal., and ! is the negation operator, ie !=== means not equal. You can also compart the value of numbers, using the greater than > or less than < operators. The following shows the basic syntax used when doing this:

var sound = "woof";
if (sound === "woof") {
  console.log("its a dog");
}
else {
  console.log("not a dog");
}

Let’s try this now. Store a number in a variable, and if it is greater than 10 print true, otherwise print false