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