Q:

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!

A:

(x1 + x2 / two)

is dividing then concatenating a string and a number.
Try
((+x1 + +x2) / two)

which uses the prefix + operator to coerce strings to numbers and parenthesizes the low-precedence addition.
You can see this in action by doing
alert(("1" + "0") / 2)  // alerts 5 since "1" + "0" == "10"
alert((1 + 0) / 2)      // alerts 0.5 since 1 + 0 == 1

A:

perhaps you need
var x1x2 = (parseInt(x1) + parseInt(x2)) / two;
var y1y2 = (parseInt(y2) + parseInt(y2)) / two;

A:

Demo jsFiddle
JS
alert("welcome to nate's midpoint calculator!");
var x1 = prompt("type your first x coordanate!");
var y1 = prompt("excellent!, 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 x1x2 = (+x1 + +x2) / 2;
var y1y2 = (+y2 + +y2) / 2 ;
alert(midText + x1x2 + "," + y1y2 + "!");

The way I would do it (jsFiddle)
HTML
<h1>Welcome to Nate's midpoint calculator!</h1>
<form>
    <div>
        <label for="x1">X1</label>
        <input type="textbox" id="x1" />
        <label for="y1">Y1</label>
        <input type="textbox" id="y1" />
    </div>
    <div>
        <label for="x2">X2</label>
        <input type="textbox" id="x2" />
        <label for="y2">Y2</label>
        <input type="textbox" id="y2" />
    </div>
    <div>
        <input type="submit" value="Calculate" onclick="Calculate()"/>
    </div>
</form>
<div>
    <span id="results"></span>
</div>

JS
function Calculate(){
    event.preventDefault();
    var x1 = parseFloat(document.getElementById('x1').value);
    var y1 = parseFloat(document.getElementById('y1').value);
    var x2 = parseFloat(document.getElementById('x2').value);
    var y2 = parseFloat(document.getElementById('y2').value);

    var x1x2 = parseFloat((x1 + +x2) / 2);
    var y1y2 = parseFloat((+y2 + +y2) / 2);
    document.getElementById("results").innerHTML=("your midpoints are: " + x1x2 + "," + y1y2 + "!");
}

Using KnockoutJS
HTML
<h1>Welcome to Nate's midpoint calculator!</h1>

<div>
    <label for="x1">X1</label>
    <input type="textbox" id="x1" data-bind="value: x1" />
    <label for="y1">Y1</label>
    <input type="textbox" id="y1" data-bind="value: y1" />
</div>
<div>
    <label for="x2">X2</label>
    <input type="textbox" id="x2" data-bind="value: x2" />
    <label for="y2">Y2</label>
    <input type="textbox" id="y2" data-bind="value: y2" />
</div>
<div> 
    your midpoints are: <span id="results" data-bind="text: Midpoint"></span>!
</div>

JS
var MidpointCalulatorViewModel = function () {
    var self = this;
    self.x1 = ko.observable();
    self.x2 = ko.observable();
    self.y1 = ko.observable();
    self.y2 = ko.observable();

    self.x1x2 = ko.computed(function () {
        return parseFloat((parseFloat(self.x1()) + parseFloat(self.x2())) / 2);
    }, self);

    self.y1y2 = ko.computed(function () {
        return parseFloat((parseFloat(self.y1()) + parseFloat(self.y2())) / 2);
    }, self);

    self.Midpoint = ko.computed(function () {
        return self.x1x2() + "," + self.y1y2();
    }, self);
};

ko.applyBindings(new MidpointCalulatorViewModel());

Note you need validation

