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