← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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