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