Looking at your post, I think maybe your formatting got a bit messed up when you copied your code. So I'm not sure if this is going to really answer your question, but here is an example:
let numberOfCake = 0;
if (numberOfCake > 0) {
console.log('Let us eat cake!');
} else {
console.log('No cake Left!');
}
This code here should work. Based off what you posted, my guess is you just have a syntax error in your code. Here is more info on how to properly structure if/else statements.
If it isn't an issue with if/else syntax, you may be running into a scope issue. For a deeper explanation of scope in javascript, check out this article.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…