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