← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. Well done, Arjun!
  2. in the console
  3. 11
  4. 10
  5. alert()
  6. 46
  7. Hi, Zoya!
  8. <script>
  9. 86
  10. 17
  11. console.log()
  12. 42
  13. if
  14. 41
  15. actions and changes
  16. 6
  17. 42
  18. 24
  19. for
  20. Welcome, Arjun!
  21. let
  22. let
  23. Well done, Riya!
  24. 91
  25. 80
  26. 10
  27. Hi, Riya!
  28. 3
  29. 12
  30. 29
  31. 6
  32. 53
  33. 80
  34. Hi, Aman!
  35. 67
  36. 67
  37. 32
  38. 30
  39. 36
  40. 81

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