WorksheetsJavaScript Input & Output Quiz
Total questions: 30
Worksheet time: 15mins
Which of the following is used to print output in the browser console?
print()
document.write()
console.log()
alert()
What does the alert() method do in JavaScript?
Prints text in console
Displays a popup message box
Writes to HTML page
Takes user input
Which method is used to take input from the user through a popup box?
console.log()
document.write()
prompt()
alert()
What does document.write("Hello"); do?
Displays a message in the console
Writes directly to the HTML page
Shows a popup
Logs an error
What type of value does prompt() return?
Number
Boolean
String
Object
Which of the following methods is used to get input from an HTML form?
prompt()
getElementById().value
console.log()
alert()
Which statement correctly outputs text without adding a new line in Node.js?
console.log("Hello");
alert("Hello");
process.stdout.write("Hello");
document.write("Hello");
Which of the following is NOT a valid browser output method?
console.log()
alert()
document.write()
process.stdout.write()
The innerHTML property is used to:
Modify the content of an HTML element
Display popup alerts
Clear console logs
Get user input
What will the following code output in the console? console.log("Hi" + 5 + 5);
Hi10
10Hi
Hi55
Error
What is the default data type returned by prompt()?
String
Number
Boolean
Null
To convert prompt input to a number, which method is used?
parseInt()
parseString()
String()
alert()
In Node.js, which module is used for taking input from users?
fs
readline
http
express
Which of the following statements is true about document.write()?
It can overwrite the entire HTML document
It runs only in Node.js
It is used for console debugging
It is the same as alert()
What will happen if you run prompt() in Node.js?
It shows an input box
It throws an error
It logs to console
It returns null
Which is the correct way to output “Hello World” inside an HTML paragraph with id demo?
document.write("Hello World");
demo.innerHTML = "Hello World";
document.getElementById("demo").innerHTML = "Hello World";
alert("Hello World");
What is the purpose of console.error()?
Prints output in red color as an error
Displays an alert box
Writes HTML code
Clears console logs
Which method is used to close the readline interface in Node.js?
rl.stop()
rl.end()
rl.close()
process.exit()
Which of the following displays a message box with OK and Cancel buttons?
prompt()
alert()
confirm()
console.log()
Which of the following will correctly print a variable’s value on the webpage? let name = "Deepan";
alert(name);
console.log(name);
document.write(name);
print(name);
console.log("JavaScript" + " Rocks!"); What will be printed in the console?
JavaScript + Rocks!
JavaScript Rocks!
undefined
Error
alert("Welcome " + "User!"); What happens when this code runs in a browser?
Prints “Welcome User!” on the webpage
Displays a popup box with “Welcome User!”
Logs text to console
Throws an error
let name = prompt("Enter your name:"); console.log("Hi " + name); If user enters Deepan, what will appear in console?
Hi name
Hi "Deepan"
Hi Deepan
Nothing will appear
document.write("Result: " + (5 + 3)); What will be displayed on the webpage?
Result: 5 + 3
Result: 8
Result: 53
Nothing, as document.write is deprecated
let x = prompt("Enter a number:"); console.log(typeof x); If user enters 10, what is logged in console?
number
string
object
undefined
let a = prompt("Enter first number:");
let b = prompt("Enter second number:");
console.log("Sum =", parseInt(a) + parseInt(b));
If user enters 5 and 7, output will be:
Sum = 57
Sum = 12
Sum = 5 + 7
Error
What will be shown inside the paragraph?
Nothing
undefined
Hello JS!
Error
process.stdout.write("Hello ");
process.stdout.write("World!");
What is printed in the terminal?
Hello World!
Hello World!
Hello only
undefined
If the user clicks Cancel, what happens?
Alert shows “File deleted”
Alert shows “Cancelled”
Nothing happens
Error
let name = "Alex";
let score = 90;
console.log(`Student ${name} scored ${score} marks.`);
What will be the console output?
Student name scored score marks.
Student Alex scored 90 marks.
Student ${name} scored ${score} marks.
undefined
