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