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