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