Logo/

JavaScript Fundamentals

Log in

Made with ScholarlyMake flashcards like these from your own notes

JavaScript Fundamentals

Questions and answers

99 cards
  1. Question:What is JavaScript primarily used for in web development?

    Answer:Provides client-side behavior and logic for 99% of websites, making them interesting, interactive, and adjustable.

  2. Question:How does JavaScript relate to HTML and CSS?

    Answer:JavaScript is a programming language like HTML and CSS.

  3. Question:What role do variables play in JavaScript code?

    Answer:Variables store data or information.

  4. Question:Give an example of data stored in a variable like a username.

    Answer:Your username.

  5. Question:What kind of data might a variable store for the price of a single t-shirt?

    Answer:The price of a single t-shirt.

  6. Question:What variable could store whether a user is logged into an account?

    Answer:Whether or not the user is logged into an account.

  7. Question:What irrational number is often stored in a variable for math calculations?

    Answer:The irrational number pi.

  8. Question:What player-related data might a variable hold in a video game?

    Answer:The player character that will show up in a video game.

  9. Question:What list of points counts as a player's hitbox in a game variable?

    Answer:A list of all the points that counts as the player's hitbox in a game.

  10. Question:What do data types refer to in variables?

    Answer:The type of data that is being stored.

  11. Question:Why is the number 2 different from the symbol "2" in data types?

    Answer:They are different types stored differently in memory.

  12. Question:What are integers in JavaScript?

    Answer:Whole numbers, positive or negative.

  13. Question:Name three examples of integer values.

    Answer:• 4 • -35 • 0

  14. Question:What are doubles in JavaScript data types?

    Answer:Decimal numbers, positive or negative.

  15. Question:Name two examples of double values.

    Answer:• 3.14 • -8.1845

  16. Question:What is a string data type?

    Answer:A series of characters in a particular order, like a word or phrase.

  17. Question:Give two examples of string values.

    Answer:• "Hello" • "Bob Cat"

  18. Question:What values does a Boolean data type hold?

    Answer:Yes or no values, always written as "true" or "false".

  19. Question:Name the two Boolean values.

    Answer:• true • false

  20. Question:What is a List/Array data type?

    Answer:An array of related values.

  21. Question:Give an example of a List/Array.

    Answer:[A, B, C...]

  22. Question:What is an Object data type?

    Answer:A collection of related values.

  23. Question:How should you read JavaScript code?

    Answer:Read all code from top to bottom for the order.

  24. Question:What does 'let name = "Obama";' declare?

    Answer:A variable named 'name' with value "Obama".

  25. Question:What does print("Thanks") output?

    Answer:Thanks

  26. Question:If name = "Obama", what does print(name) output?

    Answer:Obama

  27. Question:What is the full output of code: let name = "Obama"; print("Thanks"); print(name);

    Answer:• Thanks • Obama

  28. Question:Are semicolons required at the end of lines in this JS?

    Answer:No, you can omit/ignore them as long as you write code on new lines.

  29. Question:Why form a habit of using semicolons in JS?

    Answer:Prepares for AP Comp Sci A which requires them.

  30. Question:What is the default display command in generic JS?

    Answer:console.log(THING_TO_DISPLAY)

  31. Question:How does console.log function like print?

    Answer:It functions like print, with a new line at the end of each display.

  32. Question:What is the origin of print and println functions?

    Answer:Part of a package for introductory class and transition to AP Comp Sci A.

  33. Question:Where is (0,0) located on JS Canvas?

    Answer:Top-left corner.

  34. Question:In JS Canvas, which direction does X increase?

    Answer:To the right (normal).

  35. Question:In JS Canvas, which direction does Y increase?

    Answer:To the bottom (opposite of math).

  36. Question:Name four example points on JS Canvas.

    Answer:• (0,0) • (2,3) • (1,0) • (-1,-1)

  37. Question:What is camelCase in JS naming?

    Answer:Every word is capitalized.

  38. Question:Are all graphics in JS object data types?

    Answer:Yes.

  39. Question:How do you create a basic shape object in JS graphics?

    Answer:let shape = new Shape(parameters);

  40. Question:How do you set the color of a shape?

    Answer:shape.setColor(color);

  41. Question:How do you set the position of a shape?

    Answer:shape.setPosition(x, y);

  42. Question:How do you add a shape to the canvas?

    Answer:add(shape);

  43. Question:Where can you find documentation for specific shapes?

    Answer:Step 1: 'Docs' tab on right. Step 2: Click 'documentation'. Step 3: 'Graphics' then select shape.

  44. Question:What determines a rectangle's position?

    Answer:Its upper left corner.

  45. Question:Write the code template for creating a rectangle.

    Answer:let shape = new Rectangle(width, height);

  46. Question:What is a circle's position determined by?

    Answer:Its perfect center.

  47. Question:What is the radius of a circle?

    Answer:The distance from the center to the edge.

  48. Question:Write the code template for creating a circle.

    Answer:let shape = new Circle(radius);

  49. Question:What does stopTimer do?

    Answer:Stops your animation immediately.

  50. Question:How do you call stopTimer?

    Answer:stopTimer(function_to_stop);

  51. Question:Where should you place stopTimer in code?

    Answer:Inside an if statement.

  52. Question:What is a mouse event?

    Answer:Something that happens when input is detected from a computer's mouse.

  53. Question:Give an example of a mouse event in a video game.

    Answer:When the mouse is moved, the point-of-view camera moves.

  54. Question:Give an example of calculating with mouse clicks.

    Answer:When clicking the mouse, calculate the current clicks per second.

  55. Question:Step 1 to write mouse events: what do you create?

    Answer:Write a function to describe the instructions that happen when the mouse event occurs.

  56. Question:In mouse click CPS example, what do you track first?

    Answer:Keep track of the number of clicks.

  57. Question:In mouse click CPS, what else do you track?

    Answer:Keep track of the amount of time.

  58. Question:How do you get mouse X position in a function?

    Answer:let mousex = mouse.getX();

  59. Question:How do you get mouse Y position?

    Answer:let mousey = mouse.getY();

  60. Question:Step 2 for mouse events: what do you choose?

    Answer:Choose a mouse event that starts your function from step 1. Call that function inside.

  61. Question:Name four other mouse-related actions besides clicking.

    Answer:• Holding the mouse button down • Releasing the mouse button up • Moving • Clicking AND moving (dragging)

  62. Question:For calculating clicks per second on click, which mouse method?

    Answer:mouseClickMethod(calculate_clicks)

  63. Question:In CPS example, initialize num_clicks and time.

    Answer:let num_clicks = 0; let time = 0;

  64. Question:In calculate_clicks function, how increment clicks?

    Answer:num_clicks = num_clicks + 1

  65. Question:How compute clicks per second?

    Answer:let clicksPerSecond = numClicks / time

  66. Question:When does mouseDownMethod(fn) run?

    Answer:When the mouse is FIRST held down. Continuously while holding does not run multiple times.

  67. Question:When does mouseUpMethod(fn) run?

    Answer:When the mouse is released up.

  68. Question:When does mouseClickMethod(fn) run?

    Answer:When the mouse is pressed AND released. Must be a full click to occur.

  69. Question:When does mouseMoveMethod(fn) run?

    Answer:Whenever the mouse is moved.

  70. Question:When does mouseDragMethod(fn) run?

    Answer:Whenever the mouse is pressed down, held, AND moved (dragged across the screen).

  71. Question:Why might print be used instead of console.log?

    Answer:Makes coding accessible for introductory class.

  72. Question:What coordinate is top-left on canvas?

    Answer:(0,0)

  73. Question:Why is Y direction opposite in JS Canvas vs math?

    Answer:Y increases to the bottom.

  74. Question:What does shape.setPosition(x,y) change?

    Answer:The position of the shape.

  75. Question:Find 4 lines of code for a shape from docs.

    Answer:Change relevant pieces matching previous slide.

  76. Question:Difference between Integer and Double?

    Answer:Integers are whole numbers; Doubles are decimals.

  77. Question:Why store pi in a variable?

    Answer:Used in mathematical calculations.

  78. Question:What data type for hitbox points?

    Answer:List/Array.

  79. Question:String vs word "2"?

    Answer:String is series of characters; differs in storage.

  80. Question:Boolean always written as?

    Answer:"true" or "false".

  81. Question:Object example from text?

    Answer:A collection of related values like [A, Bob Cat].

  82. Question:Semicolons end what?

    Answer:Any coding statement.

  83. Question:console.log vs print?

    Answer:console.log is generic JS default; print adds new line.

  84. Question:What point is bottom-rightish on canvas?

    Answer:(2,3)

  85. Question:Negative coords on canvas?

    Answer:(-1,-1) possible.

  86. Question:Graphics code colored?

    Answer:Will be replaced.

  87. Question:Rectangle width/height relative to?

    Answer:Upper left corner position.

  88. Question:Circle radius from?

    Answer:Center to edge.

  89. Question:stopTimer returns?

    Answer:Does NOT return any values.

  90. Question:Place stopTimer where?

    Answer:Inside if for animation stop condition.

  91. Question:Mouse event for camera move?

    Answer:Mouse move.

  92. Question:CPS calc steps breakdown.

    Answer:• Track clicks • Track time • Increment clicks • Divide clicks by time

  93. Question:mouse.getX() returns?

    Answer:Mouse X position on screen.

  94. Question:Choose event for holding button?

    Answer:mouseDownMethod

  95. Question:Full click requires?

    Answer:Press and release for mouseClickMethod.

  96. Question:Drag needs press + ?

    Answer:Held + moved.

  97. Question:mouseDownMethod continuous?

    Answer:No, only first hold, not multiple times.

  98. Question:What happens without full release in click?

    Answer:mouseClickMethod won't run.

  99. Question:Move method for any motion?

    Answer:mouseMoveMethod(fn)