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