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