← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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