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