Question about code?


#1

so im wondering why when i use if (isSoccerFan === true) with 3 = signs the code work correctly and gives no goal but if i only use 1 = sign then it gives goal when the correct anwser is no goal so main question is why do i need 3=signs


let isSoccerFan = false 
if (isSoccerFan === true) {
  console.log("goal")}
else {
  console.log("No goal")
}


#2

= is used to assign a value to a variable. x = 5
== is used to compare values, so 5 == “5” is true.
=== is used to compare values and types, so 5 === “5” is false, one is an integer and the other a string.
In your conditional if you use if (isSoccerFan = true) you’re just assigning true to isSoccerFan, which is true.


#3

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