"declaration or statement excepted." problem
when i put an another else statement after a another else statement i get this issue. whats causing this and how can i fix it?
17 Replies
you can only have one
else
statement
you probably want another else if
for that confirmbut if i use
else if
im also gonna have to put an condition too and i dont know what to put as a condition
im just trying to make the prompt stop asking on a loop when i click cancel@Yido So you want to do that
- if there's no name, the function starts again
- otherwise the name is empty, alert and then starts the function again
- otherwise the name is not empty, asks for confirm
else? what does it have to do?
stop when the user clicks cancel and not going on a endless loop of keep asking until the user enters a name
then you can leave the else empty
nope
not working
It's going in a loop because you said
if (name === null) clicked()
so if he wants to cancel, the name is null so it starts clicked()
same thing with name === ""
oh
so i have to get rid of it to stop the loop
Yep
But why are you using prompt() btw?
Isnt a normal form better?
normal form?
i just started learning javascript from the start
Do you know html?
yeah ı do
Yeah I meant
<form>
oooh
that
i actually dont know why i didnt used that, prompt seemed better since i wanted to learn javascript
also its in the tutorial and the documentry
anyways so if i delete the null part and the name == "" then how is it supposed to stop the user when a empty value is entered
I'm not sure you can
That's probably why people use forms
This is why cancel returns null and and an empty input returns "". So stop when receiving null and tell the user the field can't be empty when receiving "".