Reputation: 63
I'm fairly new to JavaScript (even to programming, but ..) and trying to script an "easy" calculator. What I'm currently doing is trying to figure out how to do it, but I think I almost got it. For now I just want everything to work properly and only implemented an addition.
However... When pressing the "="-button it just does nothing. It throws out no results and no errors either.
<input type="button" name="ergebnis" value="=" onClick="ausgabe();">
Here is the full code: http://jsfiddle.net/bbcCB/ Please excuse the partially bilingualism of my functions, but I'm speaking German and sometimes the meaning of something is easier for me to understand in English.
Thank you very much in advance!
Upvotes: 1
Views: 181
Reputation: 259
I can't really read your code so here's a simple example of how I personally would of wrote this. http://jsfiddle.net/mtmvm/3/
html
<input type="text" id="input" value="" />
<input type="button" onclick="num_add()" id="plus" value="+" />Result: <span id="result"></span>
JS var number = 0;
var num_add = function () {
var box = document.getElementById("input");
var output = document.getElementById("result");
console.log(box.value);
number += parseFloat(box.value);
box.value = "";
output.innerHTML = number;
};
Naturally this has lots of problems mostly dealing with the fact that these functions are in the global scope meaning they may overwrite any other functions with the same name.
some good videos on javascript are David Crockford's javascript the good parts. http://www.youtube.com/results?search_query=javascript+the+good+parts&page=&utm_source=opensearch
here's a really good post on learning javascript, The best way to learn javascript
Upvotes: 0
Reputation: 4331
That code is not very well written. nor is it functional. It makes heavy use of global variables (window.X), which is discouraged these days due to global variables pollution.
Here are some better alternatives if you're looking for something to learn from:
Upvotes: 3