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