+ 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

27th Jan 2020, 8:53 PM
Gunner Beal
Gunner Beal - avatar
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
27th Jan 2020, 8:57 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 5
Gunner Beal as I said earlier: else do not take any arguments, remove the argument passed inside the else statement.
27th Jan 2020, 9:53 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 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}
27th Jan 2020, 10:00 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 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
27th Jan 2020, 9:04 PM
Daniel C
Daniel C - avatar
+ 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 {}
27th Jan 2020, 9:53 PM
Daniel C
Daniel C - avatar
+ 2
You use else to handle every condition that wasn't previously mentioned
27th Jan 2020, 9:59 PM
Daniel C
Daniel C - avatar
+ 1
It seems to me as if you are confusing JavaScript with another language and merging them together in some way.
29th Jan 2020, 12:31 AM
Andrew Johnson
Andrew Johnson - avatar
+ 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!
29th Jan 2020, 8:54 PM
Gunner Beal
Gunner Beal - avatar
0
okay, ive fixed a lot of it but now its displaying Monday and Wednesday at the same time 😭
27th Jan 2020, 9:51 PM
Gunner Beal
Gunner Beal - avatar
0
So at what point would I use else?
27th Jan 2020, 9:56 PM
Gunner Beal
Gunner Beal - avatar
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!
29th Jan 2020, 6:54 AM
Oceanlight
Oceanlight - avatar
0
You wrote tuesda instead of tuesday Your program will run perfectly now.
29th Jan 2020, 2:35 PM
Shaikh Nabeel
Shaikh Nabeel - avatar