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 does JavaScript add to a web page? (a) actions and changes (b) the page title (c) only colours (d) the domain name
-
2.⚡ What number does this code print?
let a = 27;
let b = 10;
console.log(a - b); - 3.⚡ What does alert() show? (a) a new tab (b) a pop-up box (c) a table (d) a picture
-
4.⚡ What number does this code print?
let a = 58;
let b = 18;
console.log(a + b); - 5.⚡ Which JavaScript word shows a pop-up box? (a) console.log() (b) alert() (c) if (d) for
-
6.⚡ What number does this code print?
let a = 48;
let b = 12;
console.log(a - b); -
7.⚡ What number does this code print?
let a = 11;
let b = 11;
console.log(a * b); -
8.⚡ What does this code print? (Look at the quotes!)
let x = "1";
let y = 6;
console.log(x + y); (a) 7 (b) Error (c) 16 - 9.⚡ Which JavaScript word runs code when true? (a) console.log() (b) if (c) for (d) alert()
- 10.⚡ Which JavaScript word makes a new variable? (a) if (b) let (c) for (d) alert()
-
11.⚡ What number does this code print?
let marks = 8;
marks = marks + 5;
marks = marks - 5;
console.log(marks); -
12.⚡ What number does this code print?
let score = 16;
score = score + 15;
score = score - 18;
console.log(score); -
13.⚡ What does this code show?
let name = "Arjun";
alert("Hello, " + name + "!"); (a) Hello, name! (b) name (c) Hello, Arjun! (d) Arjun -
14.⚡ What number does this code print?
let apples = 20;
apples = apples + 3;
apples = apples - 19;
console.log(apples); -
15.⚡ What number does this code print?
let a = 33;
let b = 9;
console.log(a - b); -
16.⚡ What number does this code print?
let a = 5;
let b = 1;
console.log(a + b); -
17.⚡ What does this code print? (Look at the quotes!)
let x = "8";
let y = 3;
console.log(x + y); (a) 83 (b) Error (c) 11 -
18.⚡ What does this code print? (Look at the quotes!)
let x = "9";
let y = 9;
console.log(x + y); (a) 99 (b) Error (c) 18 - 19.⚡ Which tag holds JavaScript in a page? (a) <js> (b) <style> (c) <script> (d) <code>
-
20.⚡ What number does this code print?
let a = 10;
let b = 9;
console.log(a * b); -
21.⚡ What number does this code print?
let a = 60;
let b = 33;
console.log(a - b); -
22.⚡ What does this code show?
let name = "Riya";
alert("Welcome, " + name + "!"); (a) Riya (b) Welcome, Riya! (c) Welcome, name! (d) name -
23.⚡ What number does this code print?
let apples = 11;
apples = apples + 17;
apples = apples - 14;
console.log(apples); -
24.⚡ What number does this code print?
let marks = 25;
marks = marks + 9;
marks = marks - 6;
console.log(marks); -
25.⚡ What number does this code print?
let a = 28;
let b = 9;
console.log(a + b); - 26.⚡ Which JavaScript word writes in the console? (a) console.log() (b) alert() (c) if (d) for
- 27.⚡ A JavaScript file usually ends with which extension? (a) .jpg (b) .css (c) .js (d) .html
-
28.⚡ What does this code show?
let name = "Arjun";
console.log("Hello, " + name + "!"); (a) name (b) Hello, name! (c) Hello, Arjun! (d) Arjun -
29.⚡ What number does this code print?
let a = 18;
let b = 35;
console.log(a + b); -
30.⚡ What number does this code print?
let a = 23;
let b = 14;
console.log(a - b); -
31.⚡ What number does this code print?
let score = 29;
score = score + 5;
score = score - 26;
console.log(score); -
32.⚡ What does this code print? (Look at the quotes!)
let x = "7";
let y = 2;
console.log(x + y); (a) 9 (b) 72 (c) Error -
33.⚡ What number does this code print?
let a = 19;
let b = 12;
console.log(a - b); -
34.⚡ What does this code print? (Look at the quotes!)
let x = "4";
let y = 8;
console.log(x + y); (a) Error (b) 12 (c) 48 -
35.⚡ What does this code show?
let name = "Riya";
console.log("Hello, " + name + "!"); (a) Riya (b) name (c) Hello, Riya! (d) Hello, name! -
36.⚡ What number does this code print?
let a = 3;
let b = 7;
console.log(a * b); -
37.⚡ What does this code print? (Look at the quotes!)
let x = "5";
let y = 8;
console.log(x + y); (a) 58 (b) 13 (c) Error - 38.⚡ Which JavaScript word repeats code? (a) for (b) if (c) alert() (d) let
-
39.⚡ What does this code print? (Look at the quotes!)
let x = "4";
let y = 6;
console.log(x + y); (a) Error (b) 10 (c) 46 -
40.⚡ What does this code show?
let name = "Zoya";
console.log("Hi, " + name + "!"); (a) Hi, name! (b) Hi, Zoya! (c) name (d) Zoya
Answer key
- actions and changes
- 17
- a pop-up box
- 76
- alert()
- 36
- 121
- 16
- if
- let
- 8
- 13
- Hello, Arjun!
- 4
- 24
- 6
- 83
- 99
- <script>
- 90
- 27
- Welcome, Riya!
- 14
- 28
- 37
- console.log()
- .js
- Hello, Arjun!
- 53
- 9
- 8
- 72
- 7
- 48
- Hello, Riya!
- 21
- 58
- for
- 46
- Hi, Zoya!
Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids