首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我如何循环通过这个直到我没有箭头。

我如何循环通过这个直到我没有箭头。
EN

Stack Overflow用户
提问于 2016-05-18 12:01:58
回答 1查看 28关注 0票数 0

我认为我是相当遥远,但我试图创建一个场景,在点击id 12a,我想提醒用户输入一个数字,并继续输入一个数字,直到他们用完了5个箭头。我哪里出错了?

代码语言:javascript
复制
var arrows = 5;
alert('You have ' + arrows + ' arrows!');
var shot    = prompt('How many arrows would you like to shoot?', '1');
var shotten  = parseInt(shot);

$('#12a').click(function(){
if(isNaN(shotten)){
    alert('You must enter a valid number of arrows!');
} else if(shotten > arrows){
    alert('Sorry, but there are only ' + arrows + ' arrows.  You can not shoot ' + shotten + ' arrows!');
} else if(shotten < 0){
    alert('Sorry, but you cannot shoot less than 0 arrows!');
} else {
    arrows -= shotten;
    alert('Now there are only ' + arrows + ' arrows!');
} 
});



  <p>There's a half-elf running at you. You can shoot him with your arrows if you'd like. </p>
  <p>
    <input type="submit" name="12a" id="12a" value="Let's do it.">
  </p>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-18 16:49:51

在使用JavaScript/webpage时,开发人员应该注意以下几点。

  • 如果页面的工作方式不符合您的意愿,那么首先检查您的浏览器控制台是否存在潜在问题。
  • 通常的错误可能是由于某些库丢失或未能加载例如jQuery等。
  • JS语法错误
  • 最后是逻辑错误。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37299006

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档