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