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