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