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 tag holds JavaScript in a page? (a) <style> (b) <code> (c) <js> (d) <script>
-
2.⚡ What number does this code print?
let coins = 8;
coins = coins + 6;
coins = coins - 1;
console.log(coins); -
3.⚡ 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 -
4.⚡ What number does this code print?
let a = 37;
let b = 15;
console.log(a - b); -
5.⚡ What does this code print? (Look at the quotes!)
let x = "9";
let y = 5;
console.log(x + y); (a) Error (b) 95 (c) 14 -
6.⚡ What does this code print? (Look at the quotes!)
let x = "8";
let y = 1;
console.log(x + y); (a) 9 (b) Error (c) 81 - 7.⚡ Which JavaScript word makes a new variable? (a) console.log() (b) alert() (c) for (d) let
- 8.⚡ Which JavaScript word runs code when true? (a) for (b) let (c) console.log() (d) if
-
9.⚡ What number does this code print?
let runs = 12;
runs = runs + 2;
runs = runs - 7;
console.log(runs); -
10.⚡ What number does this code print?
let a = 2;
let b = 8;
console.log(a * b); -
11.⚡ What does this code print? (Look at the quotes!)
let x = "3";
let y = 2;
console.log(x + y); (a) 5 (b) 32 (c) Error -
12.⚡ What number does this code print?
let a = 51;
let b = 6;
console.log(a + b); -
13.⚡ What number does this code print?
let a = 59;
let b = 33;
console.log(a - b); - 14.⚡ A JavaScript file usually ends with which extension? (a) .html (b) .js (c) .jpg (d) .css
-
15.⚡ What number does this code print?
let a = 55;
let b = 29;
console.log(a - b); -
16.⚡ What does this code print? (Look at the quotes!)
let x = "2";
let y = 1;
console.log(x + y); (a) 3 (b) Error (c) 21 -
17.⚡ What number does this code print?
let score = 18;
score = score + 10;
score = score - 16;
console.log(score); -
18.⚡ What does this code print? (Look at the quotes!)
let x = "5";
let y = 3;
console.log(x + y); (a) Error (b) 8 (c) 53 -
19.⚡ What does this code show?
let name = "Riya";
console.log("Well done, " + name + "!"); (a) Riya (b) Well done, Riya! (c) Well done, name! (d) name -
20.⚡ What number does this code print?
let a = 9;
let b = 1;
console.log(a + b); - 21.⚡ Which JavaScript word repeats code? (a) console.log() (b) alert() (c) let (d) for
-
22.⚡ What number does this code print?
let a = 23;
let b = 13;
console.log(a - b); -
23.⚡ What number does this code print?
let a = 58;
let b = 5;
console.log(a + b); -
24.⚡ What number does this code print?
let a = 24;
let b = 34;
console.log(a + b); -
25.⚡ What does this code print? (Look at the quotes!)
let x = "5";
let y = 2;
console.log(x + y); (a) 52 (b) Error (c) 7 -
26.⚡ What does this code print? (Look at the quotes!)
let x = "9";
let y = 7;
console.log(x + y); (a) 97 (b) Error (c) 16 - 27.⚡ Which JavaScript word shows a pop-up box? (a) for (b) let (c) if (d) alert()
- 28.⚡ Which JavaScript word writes in the console? (a) for (b) if (c) alert() (d) console.log()
-
29.⚡ What does this code print? (Look at the quotes!)
let x = "3";
let y = 8;
console.log(x + y); (a) Error (b) 11 (c) 38 -
30.⚡ What does this code show?
let name = "Zoya";
alert("Hello, " + name + "!"); (a) Zoya (b) Hello, name! (c) Hello, Zoya! (d) name - 31.⚡ Where does console.log() show its output? (a) in the console (b) in the address bar (c) on the printer (d) on the title bar
- 32.⚡ What does JavaScript add to a web page? (a) actions and changes (b) the domain name (c) the page title (d) only colours
-
33.⚡ What number does this code print?
let apples = 26;
apples = apples + 20;
apples = apples - 14;
console.log(apples); - 34.⚡ Which word makes a new variable? (a) put (b) let (c) make (d) give
-
35.⚡ What number does this code print?
let runs = 25;
runs = runs + 2;
runs = runs - 13;
console.log(runs); -
36.⚡ What number does this code print?
let marks = 9;
marks = marks + 6;
marks = marks - 10;
console.log(marks); -
37.⚡ What does this code show?
let name = "Arjun";
alert("Hi, " + name + "!"); (a) Hi, Arjun! (b) Hi, name! (c) name (d) Arjun -
38.⚡ What does this code show?
let name = "Riya";
alert("Hi, " + name + "!"); (a) Hi, Riya! (b) Riya (c) Hi, name! (d) name -
39.⚡ What does this code print? (Look at the quotes!)
let x = "8";
let y = 6;
console.log(x + y); (a) 14 (b) 86 (c) Error -
40.⚡ What does this code show?
let name = "Aman";
console.log("Well done, " + name + "!"); (a) name (b) Well done, Aman! (c) Aman (d) Well done, name!
Answer key
- <script>
- 13
- 98
- 22
- 95
- 81
- let
- if
- 7
- 16
- 32
- 57
- 26
- .js
- 26
- 21
- 12
- 53
- Well done, Riya!
- 10
- for
- 10
- 63
- 58
- 52
- 97
- alert()
- console.log()
- 38
- Hello, Zoya!
- in the console
- actions and changes
- 32
- let
- 14
- 5
- Hi, Arjun!
- Hi, Riya!
- 86
- Well done, Aman!
Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids