← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. Welcome, Riya!
  2. let
  3. alert()
  4. let
  5. 27
  6. 3
  7. 58
  8. for
  9. 3
  10. 15
  11. 75
  12. 63
  13. 56
  14. 6
  15. 41
  16. 92
  17. if
  18. 4
  19. console.log()
  20. Well done, Arjun!
  21. in the console
  22. <script>
  23. 16
  24. 10
  25. 55
  26. 27
  27. 99
  28. 83
  29. 40
  30. 21
  31. 15
  32. 2
  33. Welcome, Aman!
  34. 38
  35. 4
  36. actions and changes
  37. Welcome, Arjun!
  38. a pop-up box
  39. Well done, Zoya!
  40. 9

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