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