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