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