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