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