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