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