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