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