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