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