+ 1
What's the problem
I want to make like only alert for the specific person who enters the username correctly. Can anyone help me with it? https://code.sololearn.com/WEHQtVXp4Gtq/?ref=app
7 Respostas
+ 5
Code you wrote:
var welcome = prompt("Please enter your username with small letters:")
if (prompt == "Blugon"); {
txt = "Welcome there";
} else {
txt = "Sorry,wrong username";
}
if (prompt == "Blugon"); {
txt = "I got something for you"
}
explaining:
line 2 and line 7:
you put a semicolon after the bracket, and you check the word inputed in prompt without using the variable name.
line 3, line 5, line 8:
you wrote txt to output the text when the statement checked without declare what is the txt name, use alert or document.write instead of writing like this or just declaring the txt name in a variable.
see the fixed code below
fixed code:
var welcome = prompt("Please enter your username with small letters:")
if (welcome == "blugon") {
alert("Welcome there");
}
else {
alert("Sorry,wrong username");
}
hope it help.
+ 9
Modified Code:
https://code.sololearn.com/WjNN4lYIbETL/?ref=app
+ 4
var welcome = prompt("Please enter your username with small letters:")
if ([[welcome]] == "Blugon") {
txt = "Welcome there. I got something for you ";
} else {
txt = "Sorry,wrong username";
}
alert(txt)
+ 2
Thanks for everyone's help..i appreciate them
+ 1
delete the ";" after if (prompt == "Blugon")
+ 1
var welcome = prompt("Please enter your username with small letters:")
if (prompt == "Blugon") {
alert("Welcome there");
} else {
alert("Sorry wrong username");
}
if (prompt == "Blugon"){
alert("I got something for you");
};
0
You need to look at where ";" are needed..
You had some in the wrong place eg
"If (condition) ;{result}" should be
"if (condition) {result}" .
Furthermore each assignment eg, "x=y" should terminate with a semicolon ";" like so "x=y;"