"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?
No description
17 Replies
Mannix
Mannix3mo ago
you can only have one else statement you probably want another else if for that confirm
Yido
Yido3mo ago
but 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
Yido3mo ago
No description
lko
lko3mo ago
@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?
Yido
Yido3mo ago
stop when the user clicks cancel and not going on a endless loop of keep asking until the user enters a name
lko
lko3mo ago
then you can leave the else empty
Yido
Yido3mo ago
nope not working
lko
lko3mo ago
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 === ""
Yido
Yido3mo ago
oh so i have to get rid of it to stop the loop
lko
lko3mo ago
Yep But why are you using prompt() btw? Isnt a normal form better?
Yido
Yido3mo ago
normal form? i just started learning javascript from the start
lko
lko3mo ago
Do you know html?
Yido
Yido3mo ago
yeah ı do
lko
lko3mo ago
Yeah I meant <form>
Yido
Yido3mo ago
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
lko
lko3mo ago
I'm not sure you can That's probably why people use forms
SvenSplynter
SvenSplynter3mo ago
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 "".