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