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