Create Variable and Equal to Boolean


#1

This is the instruction for the first practice of control flow of if/else statements: Create a variable named isSoccerFan and set it equal to a boolean, based on your preference.

So i put this: let isSoccerFan = true;
It is correct right? Because it doesn’t take it as right, then my whole code is this:

let isSoccerFan = true;

if (isSoccerFan) {
  console.log('Goal!');
} else {
  console.log('No goal!');
}

Although it runs, i get an X next to the instructions…


#2

We do not have lessons on speed dial so depend upon the member to post a link with each new topic. Please post a link to the exercise.

Copy the URL from the location bar of the lesson page and paste it into a post.


#3

https://www.codecademy.com/courses/learn-javascript-control-flow/lessons/control-flow/exercises/if-else-statements?action=resume_content_item&course_redirect=introduction-to-javascript


#4

Code looks correct and should be accepted. Try a page refresh and see if that makes any difference. Sometimes switching browsers works.


#5

Looks like you’re missing the following:

if(isSoccerFan === true)

Help from CONTROL FLOW - Comparison Operators II

It can be confusing when to use one = sign and when to use three === signs.

Use a single = to assign a value to a variable. Use === to compare the values of two different variables.


#6

When a variable is a boolean, we don’t need to use a comparison.

if (isSoccerFan)

is the same thing.


#7

Good to know! Thanks for clearing that up mtf!


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.