Javascript 所有变量都具有全局范围,但函数仍然可以';我不能接近他们

Javascript 所有变量都具有全局范围,但函数仍然可以';我不能接近他们,javascript,function,global-variables,undefined,Javascript,Function,Global Variables,Undefined,我已经在代码中对所有变量进行了全局设置,但我的函数仍然无法访问它们,我相信这也会导致代码中的函数像getValueOfEasy()函数一样未定义(我的函数在定义时被称为“未定义”还有其他原因吗?) 我很感激任何帮助,我的主要问题是我不明白为什么我的变量不能被函数读取 我的代码链接如下: 代码: 函数getValueOfEasy(){ var easy=document.getElementById(“easy”).value; } 函数getValueOfMedium(){ var mediu

我已经在代码中对所有变量进行了全局设置,但我的函数仍然无法访问它们,我相信这也会导致代码中的函数像getValueOfEasy()函数一样未定义(我的函数在定义时被称为“未定义”还有其他原因吗?)

我很感激任何帮助,我的主要问题是我不明白为什么我的变量不能被函数读取

我的代码链接如下:

代码:


函数getValueOfEasy(){
var easy=document.getElementById(“easy”).value;
}
函数getValueOfMedium(){
var medium=document.getElementById(“medium”).value;
}
函数getValueOfHard(){
var hard=document.getElementById(“硬”).value;
}
var FirstE2;
var FirstM2;
var FirstH2;
var 2;
var-m2;
var第二个H2;
var ThirdE2;
var ThirdM2;
var-ThirdH2;
var FirstE;
var FirstM;
var FirstH;
var SecondE;
var SecondM;
var第二;
第三变种;
var-ThirdM;
var ThirdH;
函数timeE(){
如果(容易<4){
FirstE=“先完成你的#简单任务”;
第二,E2=3;
}else if(简单===3){
SecondE=“第二次做你的#简单作业”;
第二,E2=3;
}else if(easy=3){
FirstM=“先完成你的#中等作业”;
FirstM2=2;
}否则如果(中等===2){
SecondM=“第二次完成你的#中等作业”
第二M2=2;
}否则如果(中等===1){
ThirdM=“你的#中等作业最后完成吗”
ThirdM2=2;
}
}
函数timeH(){
如果(硬>=1){
FirstH=“先完成你的#艰巨任务”;
FirstH2=1;
}否则{
返回;
}
无功励磁;
无功励磁DM;
var-dh;
函数yesE(){
激元=3;
}
函数mehE(){
激元=2;
}
函数noE(){
激元=1;
}
功能主义{
dM=3;
}
函数mehM(){
激振dm=2;
}
函数名(){
激励dm=1;
}
功能性紫杉{
dH=3;
}
函数mehH(){
dH=2;
}
函数noH(){
dH=1;
}
函数ExcitedE(){
if(excide=3&&FirstE2=3){
FirstE=“最后完成你的#简单作业”;
}else if(excide=3&&FirstE2=3&&easy>=4){
ThirdE=“第三次完成你的#简单作业”;
}
//简单:列表第一&是的
否则,如果(Excide=2&&FirstE2=3){
SecondE=“第二次做你的#简单作业”;
} 
//简单:排名第一&可能很兴奋
else if(excide=1&&FirstE2=3){
FirstE=“先完成你的#简单作业”;
} 
//简单:排名第一&不兴奋
else if(Excide=3&&Second2=3){
SecondE=“第二次做你的#简单作业”;
}
//简单:排名第二&是的
else if(Excide=2&&Second=3){
SecondE=“第二次做你的#简单作业”;
}
//简单:排名第二,可能很兴奋
else if(excide=1&&SecondE2=3){
FirstE=“先完成你的#简单作业”;
}
//简单:第二和第二
如果(励磁端=3&&ThirdE2=3){
ThirdE=“第三次完成你的#简单作业”;
}
//简单:排名第三&是的
否则,如果(励磁端=3&&ThirdE2=3){
SecondE=“第二次做你的#简单作业”;
}
//简单:第三张名单,可能很兴奋
否则,如果(励磁端=2&&ThirdE2=3){
FirstE=“先完成你的#简单作业”;
}
//简单:第三和第三
否则,如果(励磁端=1&&ThirdE2=3){
FirstE=“先完成你的#简单作业”;
}
}
函数{
如果(excidedm=3&&FirstM2=3&&medium>=2){
ThirdM=“第三次完成你的#简单作业”;
}else if(excitem=3&&FirstE2=3){
FirstM=“最后完成你的#简单作业”;
}
//中等:列表第一名,是
if(excidedm=3&&SecondM2=3){
SecondM=“第二次做你的#简单作业”;
}
//中等:排名第二&是
否则如果(excidedm=2&&SecondM2=3){
SecondM=“第二次做你的#简单作业”;
}
//中等:排名第二,可能很兴奋
否则如果(excidedm=1&&SecondM2=3){
FirstM=“先完成你的#简单作业”;
}
//中等:第二和第二
如果(励磁DM=3&&ThirdM2=3){
ThirdM=“第三次完成你的#简单作业”;
}
//中等:排名第三&是
否则,如果(excidedm=2&&ThirdM2=3){
SecondM=“第二次做你的#简单作业”;
}
//中等:排名第三,可能很兴奋
否则,如果(excidedm=3&&ThirdM2=3){
FirstM=“先完成你的#简单作业”;
}
//中等:第三和第三
}否则{
返回;
}
函数{
如果(Excite=3&&FirstH2=3&&hard==1){
ThirdH=“最后完成你的#艰巨任务”;
}else if(Excide=3&&FirstH2=3){
FirstH=“先完成你的#艰巨任务”;
}
//难:名单第一&是的
如果(励磁端=3&&SecondH2=3){
SecondH=“第二次完成你的#艰巨任务”;
}
//难:排名第二&是的
else if(Excide=2&&SecondH2=3){
SecondH=“第二次完成你的#艰巨任务”;
}
//难:排名第二,可能很兴奋
else if(Excide=1&&SecondH2=3){
FirstH=“先完成你的#艰巨任务”;
}
//硬:第二和第二
<html>
  



  <script>

function getValueOfEasy(){    
var easy = document.getElementById("easy").value;
}
function getValueOfMedium(){
var medium = document.getElementById("medium").value;
}
function getValueOfHard(){
var hard = document.getElementById("hard").value;
}


   

<!--gives number to sentence  -->
    var FirstE2;
    var FirstM2;
    var FirstH2;
    
    var SecondE2;
    var SecondM2;
    var SecondH2;
    
    var ThirdE2;
    var ThirdM2;
    var ThirdH2;
    
    
<!-- prints __ var sentce to schedule -->
   
    var FirstE;
    var FirstM;
    var FirstH;
  
    var SecondE;
    var SecondM;
    var SecondH;
    
    var ThirdE;
    var ThirdM;
    var ThirdH;
    
  


    
    function timeE() {
    
    if (easy < 4){
            FirstE = "do your # easy assignemnts first";
        SecondE2 = 3;
    }else if (easy === 3) {
        SecondE = "do your # easy assignments second";
        SecondE2 = 3;
      } else if (easy <= 2) {
        ThirdE = "Do your # easy assignemnts last ";
        ThirdE2 = 3;
      }

    }



    function timeM() {
      if (medium >= 3) {
        FirstM = "do your # medium assignments first";
        FirstM2 = 2;
      } else if (medium === 2) {
        SecondM = "do your # medium assignments second"
        SecondM2 = 2;
      } else if (medium === 1) {
        ThirdM = "Do your # medium assignments last"
        ThirdM2 = 2;
      }
    }
    
    
    
    function timeH() {
      if (hard >= 1) {
        FirstH = "do your # hard assignments first";
        FirstH2 = 1;
      } else {
        return;
   
    }
        
      
      var excitedE;
      var excitedM;
      var excitedH;


    function yesE() {
      excitedE = 3;
    }

    function mehE() {
      excitedE = 2;
    }

    function noE() {
      excitedE = 1;
    }

    function yesM {

      excitedM = 3;
    }

    function mehM() {
      excitedM = 2;
    }

    function noM() {
      excitedM = 1;
    }

    function yesH {
      excitedH = 3;
    }

    function mehH() {
      excitedH = 2;
    }

    function noH() {
      excitedH = 1;
    }
    
    
    
    
    
    
    


    function ExcitedE() {


      if (excitedE = 3 && FirstE2 = 3) {
        FirstE = "do your # easy assignments last";

      } else if (excitedE = 3 && FirstE2 = 3 && easy >= 4) {
        ThirdE = "do your # easy  assignments third";
      }
      //easy: 1st of list & yes excited
      
      
      else if (excitedE = 2 && FirstE2 = 3) {
        
        SecondE = "do your # easy assignments Second";

      } 
      //easy: 1st of list & maybe excited
      
      
      else if (excitedE = 1 && FirstE2 = 3) {
        FirstE = "do your # easy assignments first";

      } 
      //easy: 1st of list & not excited


     else if (excitedE = 3 && SecondE2 = 3) {
        SecondE = "do your # easy assignments second";
      }
      //easy: 2nd of list & yes excited
      
      
      else if (excitedE = 2 && SecondE2 = 3) {
        SecondE = "do your # easy assignments second";
      }

      //easy: 2nd of list and maybe excited
      
      
      else if (excitedE = 1 && SecondE2 = 3) {
        FirstE = "do your # easy assignments first";
      }
      //easy: 2nd and no


      if (excitedE = 3 && ThirdE2 = 3) {
        ThirdE = "do your # easy assignments third";
      }

      //easy: 3rd of list & yes excited
      
      
      else if (excitedE = 3 && ThirdE2 = 3) {
        SecondE = "do your # easy assignments second";
      }

      //easy: 3nd of list and maybe excited
      
      
      else if (excitedE = 2 && ThirdE2 = 3) {
        FirstE = "do your # easy assignments first";
      }
      //easy: 3rd and no
      else if (excitedE = 1 && ThirdE2 = 3) {
        FirstE = "do your # easy assignments first";
      }


    }





    
    

    function ExcitedM() {

      if (excitedM = 3 && FirstM2 = 3 && medium >= 2) {
        ThirdM = "do your # easy  assignments third";
      } else if (excitedM = 3 && FirstE2 = 3) {
        FirstM = "do your # easy assignments last";
      }
      //medium: 1st of list & yes excited


      if (excitedM = 3 && SecondM2 = 3) {
        SecondM = "do your # easy assignments second";
      }
      //medium: 2nd of list & yes excited
      else if (excitedM = 2 && SecondM2 = 3) {
        SecondM = "do your # easy assignments second";
      }

      //medium: 2nd of list and maybe excited
      else if (excitedM = 1 && SecondM2 = 3) {
        FirstM = "do your # easy assignments first";
      }
      //medium: 2nd and no

      if (excitedM = 3 && ThirdM2 = 3) {
        ThirdM = "do your # easy assignments third";
      }

      //medium: 3rd of list & yes excited
      else if (excitedM = 2 && ThirdM2 = 3) {
        SecondM = "do your # easy assignments second";
      }

      //medium: 3nd of list and maybe excited
      else if (excitedM = 3 && ThirdM2 = 3) {
        FirstM = "do your # easy assignments first";
      }
      //medium: 3rd and no

    } else {

      return;
    }


  


  


    function ExcitedH() {

      if (excitedE = 3 && FirstH2 = 3 && hard === 1) {
        ThirdH = "do your # hard  assignments last";
      } else if (excitedE = 3 && FirstH2 = 3) {
        FirstH = "do your # hard assignments first";
      }
      //hard: 1st of list & yes excited


      if (excitedE = 3 && SecondH2 = 3) {
        SecondH = "do your # hard assignments second";
      }
      //hard: 2nd of list & yes excited
      else if (excitedE = 2 && SecondH2 = 3) {
        SecondH = "do your # hard assignments second";
      }

      //hard: 2nd of list and maybe excited
      else if (excitedE = 1 && SecondH2 = 3) {
        FirstH = "do your # hard assignments first";
      }
      //hard: 2nd and no

      if (excitedE = 3 && ThirdH2 = 3) {
        ThirdH = "do your # hard assignments third";
      }

      //hard: 3rd of list & yes excited
      else if (excitedE = 2 && ThirdH2 = 3) {
        SecondH = "do your # hard assignments second";
      }

      //hard: 3nd of list and maybe excited
      else if (excitedE = 3 && ThirdH2 = 3) {
        FirstH = "do your # hard assignments first";
      }
      //hard: 3rd and no

    } else {

      return;
    }




    function showSchedule() {
      document.getElementById("HD1").style.display = "none";
      document.getElementById("homeworkSchedule").style.display = "block";
    }

    function showEnterBtn() {
      document.getElementById("save").style.display = "none";
      document.getElementById("enter").style.display = "block";
    }


  function showHard() {
      document.getElementById("MD1").style.display = "none";
      document.getElementById("HD1").style.display = "block";
    }



    function showMedium() {
      document.getElementById("ED1").style.display = "none";
      document.getElementById("MD1").style.display = "block";
    }


    <
    !--makes schedule-- >
    function makeHomeworkSchedule() {

      document.getElementById("first").innerHTML = FirstE + " " + FirstM + " " + FirstH;
      document.getElementById("second").innerHTML = SecondE + " " + SecondM + " " + SecondH;
      document.getElementById("third").innerHTML = ThirdE + " " + ThirdM + " "
      ThirdH;
    }

  </script>



  <body>


    <div id=ED1>


      <p>
        <center>
          Question 1, enter number?
        </center>
      </p>

      <center><input min="0" id="easy" type="number"/></center>

      <center>
        <p>This an other question, click one of the buttons?</p>

        <button class="button button3" onclick="yesE()">Yes</button>

        <button class="button button3" onclick="mehE()">Meh</button>

        <button class="button button3" onclick="noE()">No</button>
      </center>

      <h1> </h1>




      <center><button class="button button3" onclick="getValueOfEasy(); timeE(); ExcitedE(); showMedium(); " id="easyEnter">Enter</button></center>
    </div>


    




    <div id="MD1" style="display:none">



      <h1>
        Question 2?
      </h1>

      <input min="0" id="medium" type="text">

      <p>this is another question?</p>
      <button class="button button3" onclick="yesM()">Yes</button>
      <button class="button button3" onclick="mehM()">Meh</button>
      <button class="button button3" onclick="noM()">No</button>

      <h1> </h1>



      <button class="button button3" onclick="getValueOfMedium(); showHard(); timeM(); ExcitedM();" id="mediumEnter">Enter</button>
    </div>





    <div id="HD1" style="display:none">



      <p>
       Question 3?
      </p>



      <input min="0" id="hard" type="text">

      <p>WOah another question!?</p>
      <button class="button button3" onclick="yesH()">Yes</button>
      <button class="button button3" onclick="mehH()">Meh</button>
      <button class="button button3" onclick="noH()">No</button>

      <h1> </h1>




      <button id="save" class="button button3" onclick="getValueOfHard(); timeH(); ExcitedH(); makeHomeworkSchedule();">Save</button>

      
    </div>




    <div id="homeworkSchedule" style="display:none">
      <p>... paragprah ...</p>

      <h1>1st:</h1>
      <h5 id="first"></h5>
      <h1>2nd:</h1>
      <h5 id="second"></h5>
      <h1>3rd:</h1>
      <h5 id="third"></h5>

    </div>


  </body>

</html>
// declare your variable in global

var firstVariable;


function A(firstVariable){
  // do something
}

// call function
A(firstVariable)

// if u want to check is some variable equals some value use `===` instead of '='

// don't use `<!--- -->` in JS, use `//` or `/* -your comment- */`