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