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