Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print "Hello, world!" to the console.
Javascript
console.[1]("Hello, world!");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using console.print instead of console.log
Using console.write which is not a valid method
Trying to use console.show which does not exist
✗ Incorrect
The correct method to output text to the console in JavaScript is console.log().
2fill in blank
mediumComplete the code to print the value of variable x to the console.
Javascript
let x = 10; console.[1](x);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using console.print(x)
Using console.write(x)
Using console.show(x)
✗ Incorrect
console.log(x) prints the value of x to the console.
3fill in blank
hardFix the error in the code to correctly print "Sum is 15".
Javascript
let a = 7; let b = 8; console.[1]("Sum is " + (a + b));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using console.print instead of console.log
Using console.write or console.show which are invalid
✗ Incorrect
console.log is the correct method. The code concatenates strings and numbers correctly.
4fill in blank
hardFill both blanks to print the numbers 1 to 5 using a loop.
Javascript
for(let i = 1; i [1] 5; i[2]) { console.log(i); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using i < 5 which stops at 4
Using i-- which decreases i causing an infinite loop
✗ Incorrect
The loop runs while i is less than or equal to 5, and i increments by 1 each time using i++.
5fill in blank
hardFill all three blanks to print only even numbers from 2 to 10.
Javascript
for(let num = [1]; num [2] 10; num[3]) { if(num % 2 === 0) { console.log(num); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Starting at 1 which includes odd numbers
Using < instead of <= which excludes 10
Using num-- which causes an infinite loop
✗ Incorrect
Start at 2, loop while num is less than or equal to 10, and increment num by 1 each time.