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