Training Guide: Programming in HTML5 with JavaScript and CSS3 Ebook

(Nora) #1

302 CHAPTER 6 Essential JavaScript and jQuery


Calculator.prototype.plusClick = function () {
$('#txtResult').val(Number($('#txtResult').val()) +
Number($('#txtInput').val()));
Calculator.prototype.clearEntry();
};

Calculator.prototype.minusClick = function () {
$('#txtResult').val(Number($('#txtResult').val()) -
Number($('#txtInput').val()));
Calculator.prototype.clearEntry();
};

Calculator.prototype.clearEntry = function () {
$('#txtInput').val('0');
};

Calculator.prototype.clear = function () {
$('#txtInput').val('0');
$('#txtResult').val('0');
};

return Calculator;
}());

})();


  1. Open the default.html file and add a reference to the jQuery library.
    Be sure to add the reference before the reference to the CalculatorLibrary.js file
    because that file uses jQuery. Don’t forget that you can drag and drop the file to create
    the reference. The element should look like the following.
    web Calculator





  2. At the bottom of the default.html file, change the code so that the initialize function in
    calculatorNamespace is executed when the document is ready.
    The completed default.html file should look like the following.
    <!DOCTYPE html>

    web Calculator









Free download pdf