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