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