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