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