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