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