为了账号安全,请及时绑定邮箱和手机立即绑定

我如何使这段代码给出预期的结果

我如何使这段代码给出预期的结果

HUWWW 2023-02-24 15:37:42
function myfun(){   //var yofad = document.getElementById('age').value;   var yoad;   var year = 2014 ;     if( year >= 2014){        yoad = "Your certicate is ready go to school portal";      } else if (year == 2019){        yoad = "Your certificate is in progress";      } else {        yoad = "cert not found";      }document.getElementById('cc').innerHTML=yoad}<h6>Enter your year of admission to know if your certificate is ready</h6><input id="age"><button onclick="myfun()">enter</button><p id="xc"></p><p id="cc"></p>当输入介于 2014 和 2019 之间时,我希望输出为“您的证书已准备好去学校门户网站”,当输入高于 2019 时,输出应为 cert is not read
查看完整描述

3 回答

?
江户川乱折腾

TA贡献1851条经验 获得超5个赞

只需使用并操作它会帮助您检查 2 个条件


function myfun(){

   //var yofad = document.getElementById('age').value;

   var yoad;

   var year = 2014 ;

     if( year >= 2014 && year <2019){

        yoad = "Your certicate is ready go to school portal";

      }else if (year == 2019){

       yoad = "Your certificate is in progress";

      } else {

        yoad = "cert not found";

      }

document.getElementById('cc').innerHTML=yoad

}


查看完整回答
反对 回复 2023-02-24
?
慕丝7291255

TA贡献1859条经验 获得超6个赞

将您的第一个条件限制为小于 2019,否则对于 2019、2020 和其他更大的值也将成立。改为if(year >= 14)_if(year >= 14 && year <2019)


function myfun(){

   var year = document.getElementById('age').value;

   var yoad;

     if( year >= 2014 && year < 2019){

        yoad = "Your certicate is ready go to school portal";

      } else if (year == 2019){

        yoad = "Your certificate is in progress";

      } else {

        yoad = "cert not found";

      }

document.getElementById('cc').innerHTML=yoad

}

<h6>Enter your year of admission to know if your certificate is ready</h6>

<input id="age">

<button onclick="myfun()">enter</button>

<p id="xc"></p>

<p id="cc"></p>


查看完整回答
反对 回复 2023-02-24
?
桃花长相依

TA贡献1860条经验 获得超8个赞

function myfun(){

  document.getElementById('cc').innerHTML = "";

  const value = document.getElementById('age').value;

  if (!value) return;

  

  const year = parseInt(value);

  let yoad;

  

  if (year > 2019) {

    yoad = "certicate not read";

  } else if (year >= 2014 && year <= 2019) {

    yoad = "Your certicate is ready go to school portal";

  } else {

    yoad = "cert not found";

  }

  

  document.getElementById('cc').innerHTML = yoad

}

<h6>Enter your year of admission to know if your certificate is ready</h6>

<input id="age">

<button onclick="myfun()">enter</button>

<p id="xc"></p>

<p id="cc"></p>

也许你需要这样的东西!



查看完整回答
反对 回复 2023-02-24
  • 3 回答
  • 0 关注
  • 178 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号