How to take user input in JS? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to take user input in JS?

Ok so I was learning with the sololearn "Introduction to JavaScript" course. Unlike other coding language courses I completed they never taught me how to take user input ( yes i know stuff like <textarea> and <input> in HTML but i want the input method in JS ) In the practice thingys that are at the end of every lesson i sometimes see that they use "let variable = readLine();" to take input but when i try it on the code playground it says that readLine wasn't defined. So what? Is there a system to take input through a popup just like C++ and python? And what about the readLine()? And how can i use them?

18th Mar 2023, 1:43 PM
Dronto
Dronto - avatar
4 Answers
+ 4
Have you tried using the search bar or doing a simple google search for the syntax?
18th Mar 2023, 1:45 PM
Justice
Justice - avatar
+ 3
Justice no, now i found the answer... i really forgot google was a thing 💀 So it is something like " let variable = prompt('hello world'); " Yasin Rahnaward Thanks for letting me know what's up with the readLine().
18th Mar 2023, 1:53 PM
Dronto
Dronto - avatar
18th Mar 2023, 1:48 PM
Yasin Rahnaward
Yasin Rahnaward - avatar
+ 1
It is easy. If you want to use the user input in the same site watch this video, https://www.youtube.com/watch?v=KB6Yg5hNrqc&ab_channel=KeithPaterson You will pretty much get the idea. If you want to send input to other files you would need to learn how modules in JS work. For that have a look at this, https://www.w3schools.com/js/js_modules.asp
25th Mar 2023, 10:02 AM
Harman Maan
Harman Maan - avatar