Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

//Global variables var prevCalc = 0; var calc = ; //The following function displays a number in the textfield when a number is clicked. //Note

//Global variables var prevCalc = 0; var calc = "";

//The following function displays a number in the textfield when a number is clicked. //Note that it keeps concatenating numbers which are clicked. function showNum(value) { document.frmCalc.txtNumber.value += value; }

//The following function decreases the value of displayed number by 1. //isNaN method checks whether the value passed to the method is a number or not. function decrement() { var num = parseFloat(document.frmCalc.txtNumber.value); if (!(isNaN(num))) { num--; document.frmCalc.txtnumber.value = num; } }

//The following function is called when "Add" button is clicked. //Note that it also changes the values of the global variables. function add() { var num = parseFloat(document.frmCalc.txtNumber.value); if (!(isNaN(num))) { prevCalc = num; document.frmCalc.txtNumber.value = ""; calc = "Add"; } }

//The following function is called when "Calculate" button is clicked. //Note that this function is dependent on the value of global variable. function calculate() { var num = parseFloat(document.frmCalc.txtNumber.value); if (!(isNaN(num))) { if (calc == "Add"){ var total = prevCalc + num; document.frmCalc.txtNumber.value = total; }

}

function clear() { document.frmCalc.txtNumber.value = ""; prevCalc = 0; calc = ""; } }

Can someone look at this code in javascript. The decrement function does not work properly and calculate (n-1). I also cannot figure out how to implement a subtract function and square root function. Thanks so much.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database In Depth Relational Theory For Practitioners

Authors: C.J. Date

1st Edition

0596100124, 978-0596100124

More Books

Students also viewed these Databases questions

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago