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