Computer Science G12

Fizz Quiz Thu Dec 14 2017

Problem statement

Write a constructor Vector that represents a vector in two-dimensional space. It takes x and y parameters (numbers), which it should save to properties of the same name.

Give the Vector prototype two methods, neg, plus and minus. The first returns the opposite of a vector (x,y), i.e., it returns (-x,-y). The other two take another vector as a parameter and return a new vector that has the sum or difference of the two vectors' (the one in this and the parameter) x and y values.

Add a getter property length to the prototype that computes the length of the vector -that is, the distance of the point (x, y) from the origin (0, 0)

Important remark:

  1. You must write your code such that there is as little as possible repetition of code!
  2. You must write your code as simple as possible

Submission

  1. Make sure both answer-boxes completely show your code without the need for scrolling.
  2. Print the page as a PDF file and give it the name FizzQuizz-ThuDec142017.pdf
  3. Send it as an attachment by email to msantos@dragonacademy.org

Answers

Code

Copy&Paste your code in the following text box. Drag the bottom-right corner to make sure all your lines are visible wihtout scrolling.

Test file

Copy&Paste your HTML code in the following text box. It must load your previous code and must contain the necessary test code. Drag the bottom-right corner to make sure all your lines are visible wihtout scrolling.