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