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 shows a pop-up box? (a) if (b) let (c) for (d) alert()
-
2.⚡ What number does this code print?
let a = 29;
let b = 1;
console.log(a + b); -
3.⚡ What number does this code print?
let a = 4;
let b = 3;
console.log(a * b); - 4.⚡ Which JavaScript word runs code when true? (a) alert() (b) for (c) let (d) if
- 5.⚡ What does alert() show? (a) a new tab (b) a pop-up box (c) a picture (d) a table
-
6.⚡ What does this code print? (Look at the quotes!)
let x = "5";
let y = 4;
console.log(x + y); (a) 54 (b) 9 (c) Error -
7.⚡ What number does this code print?
let a = 18;
let b = 23;
console.log(a + b); - 8.⚡ Which JavaScript word writes in the console? (a) let (b) console.log() (c) for (d) alert()
- 9.⚡ Which JavaScript word repeats code? (a) for (b) alert() (c) if (d) console.log()
-
10.⚡ What does this code show?
let name = "Arjun";
alert("Hi, " + name + "!"); (a) name (b) Hi, name! (c) Arjun (d) Hi, Arjun! -
11.⚡ What number does this code print?
let a = 4;
let b = 5;
console.log(a * b); - 12.⚡ Which word makes a new variable? (a) make (b) let (c) give (d) put
-
13.⚡ What number does this code print?
let a = 5;
let b = 6;
console.log(a * b); -
14.⚡ What does this code print? (Look at the quotes!)
let x = "6";
let y = 1;
console.log(x + y); (a) 61 (b) 7 (c) Error -
15.⚡ What number does this code print?
let a = 12;
let b = 19;
console.log(a + b); -
16.⚡ What does this code show?
let name = "Kabir";
console.log("Welcome, " + name + "!"); (a) name (b) Kabir (c) Welcome, name! (d) Welcome, Kabir! - 17.⚡ Which tag holds JavaScript in a page? (a) <style> (b) <js> (c) <code> (d) <script>
-
18.⚡ What number does this code print?
let coins = 11;
coins = coins + 19;
coins = coins - 6;
console.log(coins); -
19.⚡ What number does this code print?
let a = 15;
let b = 13;
console.log(a + b); -
20.⚡ What number does this code print?
let a = 12;
let b = 8;
console.log(a * b); -
21.⚡ What number does this code print?
let a = 5;
let b = 12;
console.log(a * b); -
22.⚡ What number does this code print?
let a = 7;
let b = 8;
console.log(a * b); -
23.⚡ What does this code print? (Look at the quotes!)
let x = "9";
let y = 8;
console.log(x + y); (a) 17 (b) 98 (c) Error -
24.⚡ What does this code print? (Look at the quotes!)
let x = "6";
let y = 2;
console.log(x + y); (a) 62 (b) Error (c) 8 -
25.⚡ What does this code print? (Look at the quotes!)
let x = "2";
let y = 4;
console.log(x + y); (a) Error (b) 6 (c) 24 -
26.⚡ What number does this code print?
let a = 20;
let b = 17;
console.log(a - b); -
27.⚡ What does this code show?
let name = "Kabir";
alert("Welcome, " + name + "!"); (a) Welcome, name! (b) Welcome, Kabir! (c) name (d) Kabir - 28.⚡ What does JavaScript add to a web page? (a) the page title (b) actions and changes (c) the domain name (d) only colours
-
29.⚡ What does this code print? (Look at the quotes!)
let x = "8";
let y = 5;
console.log(x + y); (a) 85 (b) Error (c) 13 -
30.⚡ What does this code print? (Look at the quotes!)
let x = "5";
let y = 1;
console.log(x + y); (a) Error (b) 6 (c) 51 -
31.⚡ What number does this code print?
let a = 35;
let b = 29;
console.log(a - b); -
32.⚡ What number does this code print?
let runs = 7;
runs = runs + 4;
runs = runs - 8;
console.log(runs); -
33.⚡ What number does this code print?
let runs = 17;
runs = runs + 16;
runs = runs - 8;
console.log(runs); -
34.⚡ What does this code show?
let name = "Meera";
console.log("Well done, " + name + "!"); (a) Well done, name! (b) Well done, Meera! (c) name (d) Meera -
35.⚡ What number does this code print?
let runs = 16;
runs = runs + 14;
runs = runs - 2;
console.log(runs); -
36.⚡ What number does this code print?
let a = 27;
let b = 26;
console.log(a - b); -
37.⚡ What number does this code print?
let a = 29;
let b = 20;
console.log(a + b); -
38.⚡ What number does this code print?
let marks = 27;
marks = marks + 5;
marks = marks - 1;
console.log(marks); - 39.⚡ Where does console.log() show its output? (a) in the console (b) on the title bar (c) on the printer (d) in the address bar
-
40.⚡ What number does this code print?
let a = 49;
let b = 9;
console.log(a - b);
Answer key
- alert()
- 30
- 12
- if
- a pop-up box
- 54
- 41
- console.log()
- for
- Hi, Arjun!
- 20
- let
- 30
- 61
- 31
- Welcome, Kabir!
- <script>
- 24
- 28
- 96
- 60
- 56
- 98
- 62
- 24
- 3
- Welcome, Kabir!
- actions and changes
- 85
- 51
- 6
- 3
- 25
- Well done, Meera!
- 28
- 1
- 49
- 31
- in the console
- 40
Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids