+ 1

First code, syntax error

Hello everyone, First day learning java script and I’m not quite sure why the below won’t run. I have a feeling it has something to do with the && portion? var x = "Welcome to" var y = " Katy’s Bar" document.write(x + y); var age = prompt ("what is your age"); if (age < 18) { document.write("you are not allowed in"); } else if ((age >= 18) && (age < 21)); { document.write("you can enter but cannot drink"); } else { document.write("you can enter but cant drink") }

6th Nov 2019, 2:57 PM
Alex
Alex - avatar
3 odpowiedzi
+ 2
You have a misplaced semicolon. check this line: else if((age>=18)&&(age<21)); Remove that semicolon from end of condition.
6th Nov 2019, 2:59 PM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 2
Odyel It's not necessary to put a semicolon after a statement if there is a line break. due to automatic semicolon insertion it'll work just fine.
6th Nov 2019, 3:02 PM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 1
The first 2 var needs a ;, the last document.write needs a ; and the ; after the else if statement needs to be deleted. The && part is fine Also I don't know JS but I can recognize the syntax.
6th Nov 2019, 2:59 PM
Odyel
Odyel - avatar