I’m learning HTML/CSS/JS/jQuery, and so decided to make a calculator to see if I could.
I’ve done most of the HTML/CSS design (well, basic enough CSS for it to be usable and the HTML may be subject to change), and moved onto the Javascript.
What I’m trying to do first of all is to make it so when you click on a number, it appends it to the end of the result text (unless its 0 and the result is 0).
If you look at the Javascript section in the jsFiddle link I’ve put at the bottom of this question, you can see what I tried.
I ran JSLint and got the following errors, but didn’t understand them:
Error:
Problem at line 4 character 9: Expected an assignment or function call and instead saw an expression.
val text = $(this).text();Problem at line 4 character 12: Missing semicolon.
val text = $(this).text();Implied global: $ 1,2,4,5,6, alert 3, val 4, text 4,5,6
jsFiddle link to the calculator in progress
EDIT: Also, if anyone would like to suggest a difference approach to the calculator’s HTML, please do so (I think the current method looks ugly).
EDIT 2: The val instead of var has been said. After correcting my code, the result is still not appending the number clicked. This is the question now.
EDIT 3: And as I made that edit, I found an answer has been edited to correct this.
THANKS FOR ANSWERING! 🙂
Also, here’s the working jsFiddle.
Use
varinstead ofval.. this was messing it up..Instead of
use
Also you are using this
$('#result').text().append(text);You need to append to the selector and not to the text..
Check this UPDATED FIDDLE