dynamically declare values // javascript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

dynamically declare values // javascript

My problem is: I need to pass a number to my code. I would like to do it with alert. It does not work. I am completely frustrated since I do only have this problem (with syntax of course) in javascript. How to make it work? Thanks

3rd Nov 2017, 10:31 AM
bart1bb
bart1bb - avatar
6 Answers
+ 3
alert() function only output message to user... To get an input from user you should use prompt(): var input = prompt('enter some string value:");
3rd Nov 2017, 10:36 AM
visph
visph - avatar
+ 2
It should... Provide your code to get more help ^^
3rd Nov 2017, 11:09 AM
visph
visph - avatar
+ 2
The problem is that you declare 'num' variable inside the number() function, so it does only exist in the local scope ^^
3rd Nov 2017, 11:15 AM
visph
visph - avatar
0
It does not work. I mean the value is not passed to the variable...
3rd Nov 2017, 11:06 AM
bart1bb
bart1bb - avatar
0
function number(){ var num=prompt("Give any number: "); } var x=0; var y=0; number(); x=num; y = x+2;
3rd Nov 2017, 11:12 AM
bart1bb
bart1bb - avatar
0
Thanks! I see it. It now works! :)
3rd Nov 2017, 11:17 AM
bart1bb
bart1bb - avatar