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