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