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