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