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