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