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