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