+ 1

From prompt (which is a string) to value

how to let a prompt be a value

20th May 2018, 11:21 PM
Roel
Roel - avatar
8 Réponses
+ 6
This is makes an integer of the answer. var value = parseInt(prompt("Enter number: "));
20th May 2018, 11:28 PM
John Wells
John Wells - avatar
+ 4
It worked perfectly for me. can you link your code?
20th May 2018, 11:38 PM
John Wells
John Wells - avatar
+ 4
You are using the wrong variable. Amount has the data and you are testing spnd. var amount=parseInt(prompt("enter an amount of money that is spend")); if(spnd<0){ alert("cant spend less than nothing");} else if(spnd>1000000000000){ alert("sorry, but ByteCorp doesn't have that much money"); } else if(spnd>=0&&spnd<=10000000000000){
20th May 2018, 11:41 PM
John Wells
John Wells - avatar
+ 3
Roel I did not understand your question.
20th May 2018, 11:34 PM
Ulisses Cruz
Ulisses Cruz - avatar
+ 3
in this case John Wells' answer is correct.
20th May 2018, 11:38 PM
Ulisses Cruz
Ulisses Cruz - avatar
+ 1
John Wells oh sorry already saw it, my mistake. i used the var amount for parseInt and the var spnd to check it🤦🏼‍♂️
20th May 2018, 11:40 PM
Roel
Roel - avatar
0
//doesnt work. //code: var amount=parseInt(prompt("enter an amount of money that is spend"));//i inputted 46 if(amount>=0&&amount<=100){ document.write(amount);} else{alert("enter a number")} //alerts: enter a number
20th May 2018, 11:34 PM
Roel
Roel - avatar
0
Ulisses Cruz normally, a prompt(""); is a string var x = prompt(""); is a string but i want it to be a value
20th May 2018, 11:35 PM
Roel
Roel - avatar