← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

HTML and CSS lesson 25: JavaScript basics · Set 726 · 40 questions
TalentJR

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

Answer key

  1. <script>
  2. 94
  3. let
  4. let
  5. Hi, Riya!
  6. 10
  7. .js
  8. console.log()
  9. 74
  10. for
  11. alert()
  12. 12
  13. 78
  14. 31
  15. 29
  16. in the console
  17. 75
  18. 31
  19. 35
  20. Hello, Arjun!
  21. Hello, Riya!
  22. 16
  23. 48
  24. 12
  25. 20
  26. 40
  27. 51
  28. Hello, Aman!
  29. Hi, Kabir!
  30. Welcome, Riya!
  31. 34
  32. 54
  33. Well done, Zoya!
  34. Well done, Aman!
  35. 91
  36. 63
  37. if
  38. actions and changes
  39. 22
  40. a pop-up box

Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids