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