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