0

I made var display_val = document.case.display.value; and this variable is called inside function:

run0() {
    var display_val = document.case.display.value;
    display_val  += "0"
    queue.push('0')
};

My code doesn't work and the console gives me the following error:

Uncaught TypeError: Cannot read property 'display' of undefinedat main.js:72

js:72 is var display_val = document.case.display.value;

Full html code

<html>
<head>
    <!--Copyright 2019, Aleksa Kovacevic, All rights reserved.-->
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="Online calculators for everything. Some solve problems, some satisfy curiosity." />
    <meta name="keywords" content="calculator, mortgage, loan,lease, cooking, math, college tuition, agriculture, finance,fractions,love,scientific, design, health, unit converter, pocket, running, calculators" />
    <link rel="icon" href="https://www.apkmirror.com/wp-content/uploads/2017/11/5a0aad10ea5ec.png">
    <title id= "Title">Calculator </title>
    <link href="https://fonts.googleapis.com/css?family=Inconsolata&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Roboto&display=swap" rel="stylesheet">
     <link rel="stylesheet" href="main.css" type="text/css">
     <link rel="stylesheet" href="Notiflix\node_modules\notiflix\dist\notiflix-1.8.0.min.css" />
     <script src="Notiflix\node_modules\notiflix\dist\notiflix-aio-1.8.0.js""></script>

        <script src="main.js" type="text/javascript"></script>
</head>
<body>
<button type="button" id="Git" onclick="Git()"> GitHub</button>
<div id="wrapper">
<form name="case" > <!--Buttons -->
      <input name="display" id="display" placeholder "0" onkeypress="" autofocus readonly>
    <input type="button" class="oper" value="(" onclick="runLB()">
    <input type="button" class="oper" value=")" onclick="runRB()">
    <input type="button" id="back"  class="oper"  value="CE" onclick="runBack()">
   <input type="button" id="divide"  class="oper"  value="÷" onclick="runDivide()" >

    <input type="button" class="digit" value="1" onclick="run1()">
    <input type="button" class="digit" value="2" onclick="run2()">
    <input type="button" class="digit" value="3" onclick="run3()">
    <input type="button" id="multiply"  class="oper"  value="×" onclick="runMultiply()">

    <input type="button" class="digit" value="4" onclick="run4()">
    <input type="button" class="digit" value="5" onclick="run5()">
    <input type="button" class="digit" value="6" onclick="run6()">
    <input type="button" id="minus" class="oper"  value="-" onclick="runMinus()" >

    <input type="button" class="digit" value="7" onclick="run7()">
    <input type="button" class="digit" value="8" onclick="run8()">
    <input type="button" class="digit" value="9" onclick="run9()">
    <input type="button" id="plus"  class="oper"  value="+"  onclick="runPlus()">

    <input type="button" class="digit" value="0" onclick="run0()">
    <input type="button" id="comma" class="digit" value="." onclick="runComma()">
    <input type="button" id="equal"  class="oper" value="=" onclick="runEquals()">
<div id="Cal">
<textarea  id ="TE" placeholder="Note"></textarea>
</div>
<div id="newpos">
    <!-- button rainbow -->
<button type="button" id="Note" onclick="myFunction()"> Note</button></div>

</form>
<div id="new">
<!--result textarea-->
<textarea  id="result" placeholder="History" readonly></textarea>
<button type="button" id="Del" onclick="Del()"> Delete</button>
<button type="button" id="Print" onclick="printTextArea()" > Print</button>
<button type="button" id="FP" onclick="FontP()" >Font +</button>
<button type="button" id="FM" onclick="FontM()" >Font -</button>
<button type="button" id="SaveBtn" onclick="SaveBtn" >Save</button>
</div>
</div>
</body>
Any informations will help me

1 Answers1

-2

display_val is a global variable.

To use it inside a function you have to use this.display_val instead of var