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