Beginner if else issues

I can seem to get the else statement part working ! grrrr


//let javaScriptIsPoo = "Yes"
let javaScriptIsPoo = "gghhghgg"

if (javaScriptIsPoo = "Yes") {
    console.log("Yes")
} else {
    console.log = ("No")
}

Your conditional has an assignment in it which is coercing to true

if (javaScriptIsPoo == "Yes") {
    console.log("Yes")
} else {
    console.log("No")
}

“=” is to assign value “==” is refer to “is equal to”

To be specific, what is happening here is that the assignment proceeds the evaluation so it assigns javaScriptIsPoo to "yes" before it checks anything and in this case all you are checking is wether the variable javaScriptIsPoo holds a truthy value which always does regardless of the assignment

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