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