Wednesday, 18 September 2013

dividing two variables in javascript

dividing two variables in javascript

ok, so I am trying to make a midpoint calculator in JavaScript for fun and
to practice with the language, The formula is pretty simple, it is just x1
+ x2 / 2 and y1 + y2 / 2, I want the user to be able to define the x and y
coordinates, and this is what I have come up with:
alert("welcome to nate's midpoint calculator!");
var x1 = prompt("type your first x coordanate!");
var y1 = prompt("excelent!, now your first y coordanate!");
var x2 = prompt("now type your second x coordanate!");
var y2 = prompt("and finally, your last y coordanate!");
var midText = ("your midpoints are: ");
var comma = (",");
var exclam = ("!");
var two = (2)
var x1x2 = (x1 + x2 / two);
var y1y2 = (y2 + y2 / two );
alert(midText + x1x2 + comma + y1y2 + exclam);
for some reason, this is not calculating correctly and turning in wrong
answers, go ahead and try it out. it may be some weird misstype from me, I
am fairly new to javascript, only having worked with the language for an
hour or two. any help would be very much appreciated! thanks in advance!

No comments:

Post a Comment