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.⚡ What number does this code print?
let score = 26;
score = score + 5;
score = score - 19;
console.log(score); -
2.⚡ What number does this code print?
let a = 42;
let b = 10;
console.log(a + b); - 3.⚡ Where does console.log() show its output? (a) on the title bar (b) on the printer (c) in the console (d) in the address bar
- 4.⚡ Which JavaScript word makes a new variable? (a) let (b) for (c) console.log() (d) if
-
5.⚡ What number does this code print?
let score = 23;
score = score + 7;
score = score - 25;
console.log(score); -
6.⚡ What number does this code print?
let a = 9;
let b = 17;
console.log(a + b); - 7.⚡ What does JavaScript add to a web page? (a) the domain name (b) the page title (c) only colours (d) actions and changes
- 8.⚡ Which JavaScript word repeats code? (a) if (b) alert() (c) for (d) console.log()
-
9.⚡ What number does this code print?
let a = 24;
let b = 2;
console.log(a + b); -
10.⚡ What does this code show?
let name = "Riya";
console.log("Welcome, " + name + "!"); (a) Riya (b) name (c) Welcome, name! (d) Welcome, Riya! - 11.⚡ Which tag holds JavaScript in a page? (a) <code> (b) <style> (c) <js> (d) <script>
-
12.⚡ What does this code print? (Look at the quotes!)
let x = "7";
let y = 1;
console.log(x + y); (a) 71 (b) Error (c) 8 - 13.⚡ What does alert() show? (a) a table (b) a new tab (c) a picture (d) a pop-up box
-
14.⚡ What number does this code print?
let a = 9;
let b = 9;
console.log(a * b); - 15.⚡ Which JavaScript word shows a pop-up box? (a) alert() (b) console.log() (c) for (d) let
-
16.⚡ What does this code print? (Look at the quotes!)
let x = "5";
let y = 2;
console.log(x + y); (a) Error (b) 7 (c) 52 -
17.⚡ What number does this code print?
let a = 34;
let b = 17;
console.log(a - b); -
18.⚡ What does this code print? (Look at the quotes!)
let x = "9";
let y = 7;
console.log(x + y); (a) 16 (b) 97 (c) Error -
19.⚡ What does this code show?
let name = "Kabir";
console.log("Well done, " + name + "!"); (a) Well done, name! (b) name (c) Kabir (d) Well done, Kabir! -
20.⚡ What does this code print? (Look at the quotes!)
let x = "1";
let y = 3;
console.log(x + y); (a) 4 (b) Error (c) 13 -
21.⚡ What does this code print? (Look at the quotes!)
let x = "6";
let y = 8;
console.log(x + y); (a) Error (b) 68 (c) 14 -
22.⚡ What does this code print? (Look at the quotes!)
let x = "3";
let y = 6;
console.log(x + y); (a) 9 (b) Error (c) 36 -
23.⚡ What number does this code print?
let marks = 14;
marks = marks + 3;
marks = marks - 12;
console.log(marks); -
24.⚡ What number does this code print?
let a = 53;
let b = 32;
console.log(a - b); -
25.⚡ What does this code show?
let name = "Aman";
alert("Hi, " + name + "!"); (a) Hi, Aman! (b) Aman (c) Hi, name! (d) name -
26.⚡ What does this code show?
let name = "Kabir";
alert("Welcome, " + name + "!"); (a) Kabir (b) name (c) Welcome, name! (d) Welcome, Kabir! -
27.⚡ What number does this code print?
let a = 28;
let b = 21;
console.log(a + b); -
28.⚡ What does this code print? (Look at the quotes!)
let x = "8";
let y = 6;
console.log(x + y); (a) Error (b) 86 (c) 14 -
29.⚡ What does this code print? (Look at the quotes!)
let x = "9";
let y = 1;
console.log(x + y); (a) 10 (b) Error (c) 91 -
30.⚡ What number does this code print?
let a = 31;
let b = 32;
console.log(a + b); -
31.⚡ What does this code print? (Look at the quotes!)
let x = "1";
let y = 6;
console.log(x + y); (a) 16 (b) Error (c) 7 -
32.⚡ What number does this code print?
let coins = 14;
coins = coins + 4;
coins = coins - 1;
console.log(coins); -
33.⚡ What number does this code print?
let a = 45;
let b = 10;
console.log(a + b); -
34.⚡ What number does this code print?
let a = 4;
let b = 8;
console.log(a * b); -
35.⚡ What does this code print? (Look at the quotes!)
let x = "2";
let y = 2;
console.log(x + y); (a) Error (b) 22 (c) 4 -
36.⚡ What does this code print? (Look at the quotes!)
let x = "7";
let y = 4;
console.log(x + y); (a) 11 (b) 74 (c) Error -
37.⚡ What does this code print? (Look at the quotes!)
let x = "6";
let y = 4;
console.log(x + y); (a) Error (b) 64 (c) 10 -
38.⚡ What number does this code print?
let a = 18;
let b = 38;
console.log(a + b); -
39.⚡ What number does this code print?
let apples = 15;
apples = apples + 4;
apples = apples - 7;
console.log(apples); -
40.⚡ What number does this code print?
let a = 5;
let b = 4;
console.log(a * b);
Answer key
- 12
- 52
- in the console
- let
- 5
- 26
- actions and changes
- for
- 26
- Welcome, Riya!
- <script>
- 71
- a pop-up box
- 81
- alert()
- 52
- 17
- 97
- Well done, Kabir!
- 13
- 68
- 36
- 5
- 21
- Hi, Aman!
- Welcome, Kabir!
- 49
- 86
- 91
- 63
- 16
- 17
- 55
- 32
- 22
- 74
- 64
- 56
- 12
- 20
Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids