+ 1
I need JavaScript Help
Hey guys Iâm starting JavaScript and itâs super confusing for me. Can somebody take a look at this code and tell me what Iâm doing wrong? https://code.sololearn.com/WBMr7Po9SiFD/?ref=app
14 Respostas
+ 7
There are so many mistakes in your code:
1. Function call doesn't take ":", simply use ()
2. else doesn't take any arguments
3. if/else statements don't end with a semicolon ";"
4. It's "Monday" not Monday
I think you should first learn each chapter on its own, or else you'll end up confusing yourself.
Anyway, here is a fix:
https://code.sololearn.com/WhMuJfuYOzm9/?ref=app
+ 5
Gunner Beal as I said earlier: else do not take any arguments, remove the argument passed inside the else statement.
+ 5
Anytime you want, depends on you. You didn't have to use else if, you could simply use else. The problem is that you keep passing arguments to else, like this:
else (day=="Wednesday"){do_something};
While it should be like this:
else {do_something}
+ 4
There are a few issues with this code, you should probably review the JavaScript lesson and practice while you go through.
Firstly, your first if statement:
Use the "==" or "===" sign to compare. You used "=", which is for assignment, not comparison.
Put quotes around "Monday". You cannot do if (day === Monday) because the browser will think that Monday is a variable. Instead, do if (day === "Monday")
Next, I should point out that you should not have semicolons after your if statements. Things that end in curly brackets (if statements, functions, loops, etc) should not end with semicolons.
Additionally, do not do document.write:("Your text") because there are no colors for function calls. It should just be document.write("Your text")
Finally, your else statement. Do not do else (default) {}. Instead, just do else {}
"default" is not really a variable in JavaScript, it's a function for switch statements that you will learn in the future.
https://code.sololearn.com/WGmY6q8cy3cp/?ref=app
+ 2
Gunner Beal else statements do not take any parameters. Do not do else (condition) {} because that's what else if is for. Simply do else {}
+ 2
You use else to handle every condition that wasn't previously mentioned
+ 1
It seems to me as if you are confusing JavaScript with another language and merging them together in some way.
+ 1
Oh yeah i misspelled Tuesday purposely so that it would display what you guys see. I appreciate all the feedback guys, you all helped a lot!
0
okay, ive fixed a lot of it but now its displaying Monday and Wednesday at the same time đ
0
So at what point would I use else?
0
thereâs a spelling error on line 1 in your js
it says:
var day= "Tuesda";
instead of:
var day= "Tuesday";
I think youâve already fixed most of the other big problems!
0
You wrote tuesda instead of tuesday
Your program will run perfectly now.