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