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