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