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