JavaScript Worksheet: Basics
Code tip (Line by line): let x = 5; makes a variable x holding 5; x = x + 2; changes it to 7. console.log(…) writes in the console; alert(…) shows a pop-up box. Text in quotes + anything = joined text: "5" + 3 → "53".
NameDateTime takenScore ___ / 40
- 1.⚡ Which JavaScript word writes in the console? (a) console.log() (b) if (c) alert() (d) for
-
2.⚡ What number does this code print?
let a = 3;
let b = 7;
console.log(a * b); -
3.⚡ What does this code show?
let name = "Riya";
alert("Hi, " + name + "!"); (a) name (b) Hi, name! (c) Riya (d) Hi, Riya! -
4.⚡ What does this code show?
let name = "Riya";
alert("Well done, " + name + "!"); (a) Well done, Riya! (b) Riya (c) Well done, name! (d) name -
5.⚡ What does this code show?
let name = "Aman";
alert("Hello, " + name + "!"); (a) Hello, name! (b) Aman (c) Hello, Aman! (d) name -
6.⚡ What number does this code print?
let score = 6;
score = score + 6;
score = score - 12;
console.log(score); -
7.⚡ What number does this code print?
let apples = 30;
apples = apples + 11;
apples = apples - 41;
console.log(apples); -
8.⚡ What number does this code print?
let a = 21;
let b = 26;
console.log(a + b); -
9.⚡ What number does this code print?
let a = 6;
let b = 2;
console.log(a * b); - 10.⚡ What does alert() show? (a) a new tab (b) a picture (c) a pop-up box (d) a table
- 11.⚡ Which JavaScript word runs code when true? (a) console.log() (b) alert() (c) for (d) if
-
12.⚡ What number does this code print?
let a = 7;
let b = 5;
console.log(a * b); -
13.⚡ What number does this code print?
let a = 2;
let b = 6;
console.log(a * b); - 14.⚡ Which JavaScript word makes a new variable? (a) let (b) console.log() (c) if (d) alert()
-
15.⚡ What does this code show?
let name = "Aman";
console.log("Hello, " + name + "!"); (a) Hello, name! (b) name (c) Aman (d) Hello, Aman! - 16.⚡ Which JavaScript word shows a pop-up box? (a) if (b) alert() (c) for (d) console.log()
- 17.⚡ Where does console.log() show its output? (a) in the console (b) on the printer (c) on the title bar (d) in the address bar
- 18.⚡ A JavaScript file usually ends with which extension? (a) .jpg (b) .js (c) .css (d) .html
- 19.⚡ Which tag holds JavaScript in a page? (a) <style> (b) <code> (c) <js> (d) <script>
- 20.⚡ What does JavaScript add to a web page? (a) the domain name (b) the page title (c) only colours (d) actions and changes
-
21.⚡ What does this code print? (Look at the quotes!)
let x = "5";
let y = 7;
console.log(x + y); (a) Error (b) 57 (c) 12 -
22.⚡ What does this code print? (Look at the quotes!)
let x = "7";
let y = 3;
console.log(x + y); (a) Error (b) 10 (c) 73 -
23.⚡ What does this code print? (Look at the quotes!)
let x = "4";
let y = 1;
console.log(x + y); (a) Error (b) 41 (c) 5 -
24.⚡ What number does this code print?
let a = 25;
let b = 9;
console.log(a - b); -
25.⚡ What number does this code print?
let coins = 11;
coins = coins + 4;
coins = coins - 5;
console.log(coins); -
26.⚡ What number does this code print?
let a = 25;
let b = 1;
console.log(a + b); -
27.⚡ What does this code show?
let name = "Meera";
alert("Hello, " + name + "!"); (a) Hello, Meera! (b) name (c) Meera (d) Hello, name! -
28.⚡ What number does this code print?
let score = 22;
score = score + 14;
score = score - 11;
console.log(score); -
29.⚡ What does this code show?
let name = "Meera";
alert("Well done, " + name + "!"); (a) Well done, Meera! (b) Meera (c) Well done, name! (d) name -
30.⚡ What number does this code print?
let a = 24;
let b = 11;
console.log(a - b); -
31.⚡ What number does this code print?
let books = 18;
books = books + 6;
books = books - 3;
console.log(books); - 32.⚡ Which JavaScript word repeats code? (a) for (b) alert() (c) let (d) if
-
33.⚡ What number does this code print?
let marks = 21;
marks = marks + 5;
marks = marks - 7;
console.log(marks); -
34.⚡ What does this code print? (Look at the quotes!)
let x = "3";
let y = 1;
console.log(x + y); (a) Error (b) 31 (c) 4 -
35.⚡ What number does this code print?
let apples = 19;
apples = apples + 2;
apples = apples - 12;
console.log(apples); -
36.⚡ What does this code show?
let name = "Meera";
console.log("Well done, " + name + "!"); (a) Well done, name! (b) name (c) Meera (d) Well done, Meera! -
37.⚡ What number does this code print?
let runs = 7;
runs = runs + 13;
runs = runs - 19;
console.log(runs); -
38.⚡ What number does this code print?
let coins = 5;
coins = coins + 3;
coins = coins - 1;
console.log(coins); -
39.⚡ What does this code print? (Look at the quotes!)
let x = "7";
let y = 7;
console.log(x + y); (a) 77 (b) Error (c) 14 -
40.⚡ What number does this code print?
let a = 7;
let b = 8;
console.log(a * b);
Answer key
- console.log()
- 21
- Hi, Riya!
- Well done, Riya!
- Hello, Aman!
- 0
- 0
- 47
- 12
- a pop-up box
- if
- 35
- 12
- let
- Hello, Aman!
- alert()
- in the console
- .js
- <script>
- actions and changes
- 57
- 73
- 41
- 16
- 10
- 26
- Hello, Meera!
- 25
- Well done, Meera!
- 13
- 21
- for
- 19
- 31
- 9
- Well done, Meera!
- 1
- 7
- 77
- 56
Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids