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