Математические операции с использованием замыканий
Это оператор калькулятора, использующий функцию замыкания.
Он не показывает результат по выбору пользователя пожалуйста помогите мне
в результирующем блоке он также отображается как NaN после преобразования его в целое число.
Что я уже пробовал:
//HTML-код
<pre><html> <head> <title> Closures on Arithmatic Operations</title> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="ClosuresArithmatic.js"></script> <script type="text/javascript" src="mathematicalOperatons.js"></script> <style type="text/css"> .block{ width: 500px; height: 500px; border: 1px solid black; background-color: #ccc; } li{ list-style: none; padding: 5px; } #showvalues{ display: none; } </style> </head> <body> <div class="block"> <ul> <li> Enter the First Number : <input type="text" name="fnumber" id="fnumber"> </li> <li> Enter the second Number : <input type="text" name="fnumber" id="snumber"> </li> <li> Type of Arithmatic Operations <select id="operation"> <option value="">Arithatic Operations</option> <option value="add">Addition</option> <option value="sub">Subtraction</option> <option value="mul">Multiplication</option> <option value="divn">Division</option> </select> </li> </ul> <input type="button" value="Submit Values" onclick="return calculate_operations()"> <div id="showvalues"> <ul> <li> Entered first Number is : <span id="numberF" /> </li> <li> Entered second Number is : <span id="numberS" /> </li> <li> Type of Operation Selected : <span id="sel_operation"></span> </li> <li> Result is : <span id="result_block" /> </li> </ul> </div> </div> </body> </html>
// Код Java-Скрипта
function calculate_operations(){ var details = {} details.Firstvalue = document.querySelector("#fnumber").value; details.SecondValue = document.querySelector("#snumber").value; details.Firstvalue = parseInt(details.Firstvalue); details.SecondValue = parseInt(details.SecondValue); details.result = 0; //details.selectedOperation = document.querySelector("operation") details.showdetails = function(){ //console.log(pradeep); document.querySelector("#numberF").innerText = details.Firstvalue; document.querySelector("#numberS").innerText = details.SecondValue; function operationsMathematical(){ if (document.querySelector("#operation".value == "")) { document.querySelector("#sel_operation").innerText = +"No operation selected"; } if (document.querySelector("#operation").value== "add") { document.querySelector("#sel_operation").innerHTML =+details.Firstvalue +"+" +details.SecondValue ; details.result= pradeep.manupulation_value(details.Firstvalue,details.SecondValue); details.result=parseInt(pradeep.manupulation_value(sum_is)); document.querySelector("#result_block").innerHTML = +details.result; } if (document.querySelector("#operation").value== "sub") { document.querySelector("#sel_operation").innerText =+details.Firstvalue +"-" +details.SecondValue; details.result= pradeep.manupulation_value(details.Firstvalue,details.SecondValue); details.result=parseInt(pradeep.manupulation_value(sub_is)); document.querySelector("#result_block").innerHTML = +details.result; } if (document.querySelector("#operation").value== "mul") { document.querySelector("#sel_operation").innerText =+details.Firstvalue +"*" +details.SecondValue; details.result= pradeep.manupulation_value(details.Firstvalue,details.SecondValue); details.result=parseInt(pradeep.manupulation_value(mul_is)); document.querySelector("#result_block").innerHTML = +details.result; } if (document.querySelector("#operation").value== "divn") { document.querySelector("#sel_operation").innerText =+details.Firstvalue +"/" +details.SecondValue; details.result= pradeep.manupulation_value(details.Firstvalue,details.SecondValue); details.result=parseInt(pradeep.manupulation_value(divn_is)); document.querySelector("#result_block").innerHTML = +details.result; } } operationsMathematical(); } //details.result= pradeep.manupulation_value(details.Firstvalue,details.SecondValue); document.querySelector("#showvalues").style.display="block"; details.showdetails(); }
// Код Закрытия
var pradeep=(function(){ //result = 0; sum_is=sub_is=mul_is=divn_is=0; function manupulation(x,y){ var sum_is = getsumValues(x,y); var sub_is = getsubValues(x,y); var mul_is = getmulValues(x,y); var divn_is = getdivnValues(x,y); return [sum_is,sub_is,mul_is,divn_is]; } function getsumValues(x,y){ var sum_is = x+y; return sum_is; } function getsubValues(x,y){ var sub_is = x-y; return sub_is; } function getmulValues(x,y){ var mul_is = x*y; return mul_is; } function getdivnValues(x,y){ var divn_is = x/y; return divn_is; }return{ manupulation_value : function(x,y){ return manupulation(x,y); } } })();