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