← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 81
  2. 6
  3. Welcome, Meera!
  4. 7
  5. if
  6. 97
  7. 12
  8. let
  9. alert()
  10. 10
  11. 40
  12. 68
  13. 47
  14. 88
  15. 1
  16. console.log()
  17. in the console
  18. 76
  19. Well done, Riya!
  20. Welcome, Aman!
  21. Welcome, Arjun!
  22. 6
  23. Hello, Meera!
  24. 74
  25. for
  26. 14
  27. 24
  28. let
  29. 61
  30. 72
  31. 42
  32. 7
  33. a pop-up box
  34. 13
  35. actions and changes
  36. 3
  37. 2
  38. 71
  39. 50
  40. <script>

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