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