← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 41
  2. actions and changes
  3. <script>
  4. let
  5. alert()
  6. in the console
  7. for
  8. console.log()
  9. Hello, Zoya!
  10. let
  11. 6
  12. 21
  13. 45
  14. if
  15. 70
  16. 62
  17. 9
  18. 18
  19. Welcome, Zoya!
  20. Hello, Kabir!
  21. 32
  22. 21
  23. 45
  24. 52
  25. 9
  26. 54
  27. 19
  28. Hi, Riya!
  29. 95
  30. 44
  31. 39
  32. 49
  33. 74
  34. 89
  35. 82
  36. Hi, Aman!
  37. Welcome, Riya!
  38. Hello, Aman!
  39. 6
  40. 2

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