Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please edit the code based on the instructions provided. Languages: javascript and html will upvote! ---------------------------------------------------------------------------------------- --------------------------------------------------------- html file: Calculator My Calculator This web page

Please edit the code based on the instructions provided.

Languages: javascript and html

will upvote!

----------------------------------------------------------------------------------------

image text in transcribed

--------------------------------------------------------- html file: 
   Calculator           
 

My Calculator

Please enter a numeric value or use the number buttons below.









Validate HTML Validate CSS

--------------------------------------------------------

//javascript code:

//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) { // error fixed: changed to += from +== 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 increment() { var num = parseFloat(document.frmCalc.txtNumber.value); if (!(isNaN(num))) { num++; document.frmCalc.txtNumber.value = num; } } //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; } } function sqrt() { var num = parseFloat(document.frmCalc.txtNumber.value); if (!(isNaN(num))) { num = Math.sqrt(num); document.frmCalc.txtNumber.value = num; } } function power2() { var num = parseFloat(document.frmCalc.txtNumber.value); if (!(isNaN(num))) { num = Math.pow(num,2); document.frmCalc.txtNumber.value = num; } } function floor() { var num = parseFloat(document.frmCalc.txtNumber.value); if (!(isNaN(num))) { num = Math.floor(num); document.frmCalc.txtNumber.value = num; } } function round() { var num = parseFloat(document.frmCalc.txtNumber.value); if (!(isNaN(num))) { num = Math.round(num); document.frmCalc.txtNumber.value = num; } } function powern() { var num = parseFloat(document.frmCalc.txtNumber.value); if (!(isNaN(num))) { prevCalc = num; document.frmCalc.txtNumber.value = ""; calc = "Pow"; } } //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 "Sub" button is clicked. //Note that it also changes the values of the global variables. function sub() { var num = parseFloat(document.frmCalc.txtNumber.value); if (!(isNaN(num))) { prevCalc = num; document.frmCalc.txtNumber.value = ""; calc = "Sub"; } } function mul() { var num = parseFloat(document.frmCalc.txtNumber.value); if (!(isNaN(num))) { prevCalc = num; document.frmCalc.txtNumber.value = ""; calc = "Mul"; } } function divide() { var num = parseFloat(document.frmCalc.txtNumber.value); if (!(isNaN(num))) { prevCalc = num; document.frmCalc.txtNumber.value = ""; calc = "Div"; } } //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"){ // chaged to prevCalc var total = prevCalc + num; } else if (calc == "Sub"){ // chaged to prevCalc var total = prevCalc - num; } else if (calc == "Pow"){ // chaged to prevCalc var total = Math.pow(prevCalc, num); } else if (calc == "Mul"){ // chaged to prevCalc var total = prevCalc*num; } else if (calc == "Div"){ // chaged to prevCalc var total = prevCalcum; } document.frmCalc.txtNumber.value = total; }} function clear() { document.frmCalc.txtNumber.value = ""; prevCalc = 0; calc = ""; }

---------------------------------------------------------------------------------------

//css code ( nothing done to this):

/*ITIS 3135 Activity 5 css file*/ body { font-family:"arial"; } /*Make it look more like a calculator*/ #calc { width:250px; background-color:#cccccc; text-align:center; border:outset; padding:5px; } /*Change the style of the buttons*/ input { font-family:"Courier New"; text-align:right; } /*Make the buttons that have not been implemented red*/ input.implement { background-color:red; }

Part 1: Apply Separation of concerns 1. Your files currently contain embedded code, specifically there is embedded JavaScript (JS) in the HTML file. (e.g. onclick="showNum(4)") 2. Make the calculator function accurately without any embedded JS code. 3. Check out the Week5-JS-Demo to see how you can call JS event handlers like onclick from the JS file. Then remove the JS event handlers (e.g. onclick="showNum(4)) from the HTML file of activity 7, and call it from the JS page. You will have to do corresponding changes in the HTML file as well. 4. Hint: here is how you can implement showNum() in the JS file window.onload = function () { document.getElementById("btn").onclick = showNum; /*btn4 is the id of the button that has a value of 4*/ } function showNum() { document.frmCalc. txtNumber.value += this.value; } a. c. 5. For a binary operator, you must click on the buttons in the following order (e.g. addition): Hit a number button b. Hit the "+' button Hit a number button d. Hit the 'Calculate button 6. For a unary operator, you must click the buttons in the following order (e.g. decrement): a. Hit the number button b. Hit the button 7. All operators must work. 8. Validate any HTML CSS and/or JavaScript errors. To validate your HTML/CSS you can use either of the three methods- By URI (copy paste specific file path on the server), By file upload (uploading the file), or By direct input(copy paste the content of the file) on the validation link

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

Big Data 29th British National Conference On Databases Bncod 2013 Oxford Uk July 2013 Proceedings Lncs 7968

Authors: Dan Olteanu ,Georg Gottlob ,Christian Schallhart

2013th Edition

3642394663, 978-3642394669

More Books

Students also viewed these Databases questions

Question

What Is acidity?

Answered: 1 week ago

Question

Explain the principles of delegation

Answered: 1 week ago

Question

State the importance of motivation

Answered: 1 week ago

Question

Discuss the various steps involved in the process of planning

Answered: 1 week ago

Question

What are the challenges associated with tunneling in urban areas?

Answered: 1 week ago