Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
64 views
in Technique[技术] by (71.8m points)

javascript - It is undefined

I am just practicing code and it says error: Uncaught ReferenceError: numberofCake is not defined the I need help to find what causes it to not be defined the code is

let numberOfCake = 0;
  console.log('Let us eat cake!');
} else {
  console.log('No cake Left!');
}
question from:https://stackoverflow.com/questions/65853289/it-is-undefined

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...