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