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