Activity: Conditionals

Let's do the following exercises with a partner. Grab a couple new neighbors and together go through each of these exercises one at a time. At the end we will ask different groups to present their solutions to each of the challenges and to explain why that is the right answer.

For each of these exercises, make a variable at the top containing the given data and below we'll write some if statements!

Log Greetings

Write a program that logs a different greeting for various different userNames. Try changing the userName at the top and see the different greetings be logged.

Primary Colors

Given a string that is the name of a color, log if the color is a primary color or not.

Even or Odd

Given an integer, log if the integer is even or odd. Hint: Google JavaScript's modulo operator

Using Arrays

Given an array, log if the array is empty or not. Hint: What property do arrays have that is useful to answer this question?

What's wrong with this code?

if myVariable = 10 {
  console.log("myVariable was equal to 10")
else {
  console.log("myVariable was NOT equal to 10")
}