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