← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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