0
How is this still wrong?
I don't understand what this bug is Getting user input Example Welcome, tom! let name = readLine(); console.log("Welcome," + name + "!");
7 Réponses
+ 6
Novan Rizky Setiawan
The issue in your code is that the `readLine()`,this function is not valid JavaScript.
The correct function to use for getting user input in JavaScript is `prompt()`.
By using the `prompt()` function, a dialog box will appear where the user can input their name.
See this modified version..
let name = prompt("Enter your name:");
console.log("Welcome, " + name + "!");
Note that..
Both `readline` and `prompt` are used to get user input in JavaScript, but they have different use cases.
#`readline`: this module in Node.js that allows you to read input from the command line. It is commonly used for creating command-line interfaces or interactive command-line applications.
#`prompt`this built-in function in web browsers that used to display a dialog box and get user input. It is commonly used for simple user interactions within a web page.
Otherhand:-
If you're having trouble in code, share your code and describe what error message you're receiving.
+ 2
Create a readline interface and use question method to prompt the user for input
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Enter your name: ', function(name) {
console.log("Welcome, " + name + "!");
rl.close();
});
If readline not defined import by
const readline = require('readline');
Ensure that you're running the code in a terminal or command prompt, not within a code editor or an integrated development environment (IDE).
+ 1
But it doesn't work, it says there is a problem with the prompt, this is a stage in one of the javascript introductions in solo learn
The title is string concatenation, I think I put the wrong code when I follow all the code the solution is the same
What is a should i do? If the solution code is wrong
+ 1
Spaces are important in code coaches.
0
Novan Rizky Setiawan ,
Could you kindly show your attempt here?
0
I made the same mistake the other day. You need to have a space after the comma in Welcome so the output will format correctly.
Like this:
console.log("Welcome, " + name + "!");
Hope this helps.