Ajax-loader-large-white
Animate Your Name
Decisions, decisions

Great job! Next let's use booleans to decide whether a block of code should run. Take a look at this code:

if(10 < 3) {
    bubbleShape = "circle";
}

else {
    bubbleShape = "square";
}

Now imagine we have a robot that starts in line 1 of this code, and walks down it line by line. If the condition (in this case, 10 < 3) evaluates to true, then the robot runs the code inside the first pair of curly braces {}, which will make the bubbles circle-shaped.

Else the condition is false (which it is, in this case), so the robot skips the code in the first block of curly braces entirely, and runs the code in the second block. Therefore, the bubbles will be square-shaped.

This is called an if/else statement.

Instructions

Let's add an if/else statement to our program.

  1. Delete bubbleShape = "square" in line 9 of your code
  2. Replace it with an if/else statement that makes the bubbles circle-shaped. Use the if/else statement in the example above to get started. Remember to imagine a robot walking down your if/else statement line by line.
?
Stuck? Get a hint! Hint
Get live, fast support from Codecademy Advisors when you get stuck. Learn more.

First we want an if block. If a condition evaluates to true, then the robot will run the code inside this block.

if(15 > 5) {
    bubbleShape = "circle";
}

Second we want an else block. The robot will skip this code because the condition in the if block above evaluated to true.

else {
    bubbleShape = "square";
}

All together, the **if/else statement** looks like this:

if(15 > 5) {
bubbleShape = "circle";
}

else {
bubbleShape = "square";
}

main.js
index.html
project
View Preview