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