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