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