+ 1
Help me to make it true.never I could to work with return statment.
10 Answers
+ 1
I don't realy understand what you are trying to achive, can you ellaborate?
+ 1
I want take a name from user and if the value of prompt was nothing it returns the promt again
+ 1
I know but I want to do that with return to learn working with return
+ 1
it's with do wile
do{
var pr = prompt("Enter your name")
}
while(pr == "")
+ 1
0
Make a while loop using the statement (x!="") were x is the prompt
0
make the return statememt value to a(), which will make the function repet until the user gives input
0
For one your using an assignment operator in the 'if' statement. Secondly you need to have some sort of recursion weather it's a loop or having the function call itself.
Here's an example using your code:
x = "";
while(x == "") x = prompt("Enter your name");
return x;
0
function a() {
var x = prompt("Enter your name")
if (x == "") {
return a();
}
}
a()
// Is this what you want? It'll keep asking for input till the input isn't nothing
0
yes