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