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