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 = 3;
let b = 11;
console.log(a * b); -
2.⚡ What number does this code print?
let a = 27;
let b = 3;
console.log(a - b); - 3.⚡ A JavaScript file usually ends with which extension? (a) .html (b) .jpg (c) .css (d) .js
-
4.⚡ What does this code print? (Look at the quotes!)
let x = "8";
let y = 1;
console.log(x + y); (a) 9 (b) Error (c) 81 - 5.⚡ Which JavaScript word runs code when true? (a) console.log() (b) let (c) for (d) if
- 6.⚡ What does alert() show? (a) a picture (b) a pop-up box (c) a new tab (d) a table
-
7.⚡ What number does this code print?
let score = 14;
score = score + 5;
score = score - 11;
console.log(score); -
8.⚡ What does this code print? (Look at the quotes!)
let x = "1";
let y = 7;
console.log(x + y); (a) Error (b) 17 (c) 8 - 9.⚡ Which JavaScript word makes a new variable? (a) alert() (b) if (c) console.log() (d) let
- 10.⚡ Which JavaScript word shows a pop-up box? (a) for (b) alert() (c) let (d) console.log()
-
11.⚡ What number does this code print?
let a = 44;
let b = 40;
console.log(a + b); - 12.⚡ Which tag holds JavaScript in a page? (a) <style> (b) <script> (c) <code> (d) <js>
-
13.⚡ What number does this code print?
let a = 33;
let b = 31;
console.log(a - b); -
14.⚡ What does this code show?
let name = "Riya";
console.log("Welcome, " + name + "!"); (a) Welcome, Riya! (b) Welcome, name! (c) Riya (d) name -
15.⚡ What number does this code print?
let apples = 16;
apples = apples + 10;
apples = apples - 7;
console.log(apples); -
16.⚡ What number does this code print?
let a = 40;
let b = 28;
console.log(a - b); -
17.⚡ What does this code print? (Look at the quotes!)
let x = "9";
let y = 4;
console.log(x + y); (a) 94 (b) Error (c) 13 -
18.⚡ What does this code print? (Look at the quotes!)
let x = "5";
let y = 7;
console.log(x + y); (a) 57 (b) Error (c) 12 -
19.⚡ What does this code print? (Look at the quotes!)
let x = "7";
let y = 4;
console.log(x + y); (a) Error (b) 74 (c) 11 -
20.⚡ What does this code print? (Look at the quotes!)
let x = "2";
let y = 9;
console.log(x + y); (a) 11 (b) Error (c) 29 -
21.⚡ What does this code print? (Look at the quotes!)
let x = "4";
let y = 2;
console.log(x + y); (a) 42 (b) Error (c) 6 -
22.⚡ What does this code print? (Look at the quotes!)
let x = "3";
let y = 9;
console.log(x + y); (a) Error (b) 12 (c) 39 -
23.⚡ What number does this code print?
let a = 42;
let b = 2;
console.log(a + b); - 24.⚡ Which JavaScript word repeats code? (a) console.log() (b) if (c) for (d) let
-
25.⚡ What number does this code print?
let a = 2;
let b = 8;
console.log(a * b); -
26.⚡ What number does this code print?
let a = 49;
let b = 34;
console.log(a + b); - 27.⚡ Which word makes a new variable? (a) make (b) give (c) let (d) put
- 28.⚡ Which JavaScript word writes in the console? (a) console.log() (b) let (c) for (d) alert()
-
29.⚡ What number does this code print?
let coins = 30;
coins = coins + 17;
coins = coins - 38;
console.log(coins); -
30.⚡ What does this code print? (Look at the quotes!)
let x = "4";
let y = 6;
console.log(x + y); (a) 46 (b) 10 (c) Error -
31.⚡ What does this code print? (Look at the quotes!)
let x = "9";
let y = 1;
console.log(x + y); (a) Error (b) 91 (c) 10 -
32.⚡ What number does this code print?
let marks = 8;
marks = marks + 14;
marks = marks - 15;
console.log(marks); -
33.⚡ What number does this code print?
let score = 8;
score = score + 16;
score = score - 3;
console.log(score); - 34.⚡ 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
-
35.⚡ What number does this code print?
let apples = 5;
apples = apples + 15;
apples = apples - 6;
console.log(apples); -
36.⚡ What does this code print? (Look at the quotes!)
let x = "3";
let y = 7;
console.log(x + y); (a) Error (b) 10 (c) 37 -
37.⚡ What number does this code print?
let a = 11;
let b = 4;
console.log(a * b); -
38.⚡ What does this code show?
let name = "Arjun";
console.log("Hello, " + name + "!"); (a) Arjun (b) name (c) Hello, Arjun! (d) Hello, name! -
39.⚡ What number does this code print?
let books = 26;
books = books + 8;
books = books - 11;
console.log(books); -
40.⚡ What does this code print? (Look at the quotes!)
let x = "2";
let y = 2;
console.log(x + y); (a) Error (b) 22 (c) 4
Answer key
- 33
- 24
- .js
- 81
- if
- a pop-up box
- 8
- 17
- let
- alert()
- 84
- <script>
- 2
- Welcome, Riya!
- 19
- 12
- 94
- 57
- 74
- 29
- 42
- 39
- 44
- for
- 16
- 83
- let
- console.log()
- 9
- 46
- 91
- 7
- 21
- in the console
- 14
- 37
- 44
- Hello, Arjun!
- 23
- 22
Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids