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