What is the simplest way to display a message in JavaScript?
Use console.log('Your message'); to print a message to the browser's console.
Click to reveal answer
beginner
What does console.log('Hello, world!'); do?
It prints the text Hello, world! to the browser's console, which is a place to see messages from your program.
Click to reveal answer
beginner
Where do you write JavaScript code to run it in a web browser?
You can write JavaScript inside a <script> tag in an HTML file or in a separate .js file linked to the HTML.
Click to reveal answer
beginner
How do you run your first JavaScript program in a browser?
Open your HTML file with the JavaScript code in a web browser, then open the browser's developer console to see the output.
Click to reveal answer
beginner
Why is console.log() useful when learning JavaScript?
It helps you see what your program is doing by showing messages, making it easier to understand and find mistakes.
Click to reveal answer
Which JavaScript command prints text to the console?
Aecho()
Bprint()
Cconsole.log()
Dwrite()
✗ Incorrect
console.log() is the correct way to print messages to the browser console.
Where do you put JavaScript code inside an HTML file?
A<head> tag only
B<script> tag
C<body> tag only
D<style> tag
✗ Incorrect
JavaScript code goes inside the <script> tag, which can be placed in <head> or <body>.
What do you need to open to see the output of console.log()?
ABrowser console
BHTML page
CText editor
DCommand prompt
✗ Incorrect
The browser console shows messages printed by console.log().
Which file extension is used for JavaScript files?
A.js
B.java
C.html
D.css
✗ Incorrect
JavaScript files use the .js extension.
What is the purpose of writing your first JavaScript program?
ATo create a website layout
BTo write text documents
CTo design images
DTo learn how to make the computer do things
✗ Incorrect
Writing your first JavaScript program helps you learn how to tell the computer what to do.
Explain how to write and run your first JavaScript program in a web browser.
Think about where the code goes and how you see the result.
You got /4 concepts.
Why is using console.log() helpful when starting to learn JavaScript?
Consider how you check what your program does.
You got /4 concepts.
Practice
(1/5)
1. What does the console.log() function do in JavaScript?
easy
A. It changes the background color of the page.
B. It creates a pop-up alert on the screen.
C. It stops the program from running.
D. It shows messages in the browser console.
Solution
Step 1: Understand the purpose of console.log()
This function is used to display messages or values in the browser's console, which helps developers see output or debug.
Step 2: Compare with other options
Options A, B, and D describe different actions that console.log() does not perform.
Final Answer:
It shows messages in the browser console. -> Option D
Quick Check:
console.log() shows messages [OK]
Hint: Remember: console.log prints messages to the console [OK]
Common Mistakes:
Thinking console.log creates alerts
Confusing console.log with styling commands
Assuming console.log stops the program
2. Which of the following is the correct syntax to print "Hello, World!" in JavaScript?
easy
A. print("Hello, World!");
B. console.log("Hello, World!");
C. echo "Hello, World!";
D. System.out.println("Hello, World!");
Solution
Step 1: Identify JavaScript syntax for output
JavaScript uses console.log() to print messages to the console.
Step 2: Check other options for language mismatch
A is Python style, B is Java style, C is PHP style, so they are incorrect for JavaScript.
Final Answer:
console.log("Hello, World!"); -> Option B
Quick Check:
JavaScript output uses console.log() [OK]
Hint: Use console.log() to print messages in JavaScript [OK]
Common Mistakes:
Using print() instead of console.log()
Confusing JavaScript with other languages
Missing parentheses or semicolon
3. What will be the output of the following code?
console.log('Hi');
console.log('There');
medium
A. Hi
There
B. Hi There
C. Hi\nThere
D. HiThere
Solution
Step 1: Understand console.log behavior
Each console.log() prints its message on a new line in the console.
Step 2: Analyze the output lines
The first prints "Hi", then the second prints "There" on the next line, so output is two lines: "Hi" then "There".
Final Answer:
Hi
There -> Option A
Quick Check:
console.log prints each message on a new line [OK]
Hint: Each console.log prints on a new line automatically [OK]
Common Mistakes:
Thinking console.log joins messages on one line
Confusing \n as literal text instead of newline
Ignoring line breaks between calls
4. Find the error in this JavaScript code:
console.log('Hello World')
medium
A. console.log is misspelled
B. Incorrect quotes used
C. No error, code is correct
D. Missing semicolon at the end
Solution
Step 1: Check syntax correctness
The code uses correct function name, quotes, and parentheses.
Step 2: Consider JavaScript semicolon rules
Semicolons are optional at the end of statements in JavaScript, so missing semicolon is not an error.
Final Answer:
No error, code is correct -> Option C
Quick Check:
JavaScript allows optional semicolons [OK]
Hint: Semicolons are optional but recommended; no error here [OK]
Common Mistakes:
Thinking missing semicolon causes error
Confusing quote types as error
Assuming console.log is misspelled
5. You want to write a JavaScript program that prints your name and age on separate lines. Which code will do this correctly?
hard
A. console.log('Name: John'); console.log('Age: 25');
B. console.log('Name: John\nAge: 25');
C. console.log('Name: John' + 'Age: 25');
D. console.log('Name: John Age: 25');
Solution
Step 1: Understand printing on separate lines
Using two console.log() calls prints each message on its own line.
Step 2: Check other options for line breaks
console.log('Name: John\nAge: 25'); uses \n which creates a newline in the output; console.log('Name: John' + 'Age: 25'); joins to 'Name: JohnAge: 25' on one line; console.log('Name: John Age: 25'); prints all on one line.
Final Answer:
console.log('Name: John'); console.log('Age: 25'); -> Option A
Quick Check:
Separate console.log calls print on separate lines [OK]
Hint: Use separate console.log() for each line [OK]
Common Mistakes:
Using + without spaces causing joined text
Thinking \n creates a newline (prints literal \n)
Printing all info in one console.log without breaks
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.