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