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