0
Я думаю, что я довольно далеко, но я пытаюсь создать сценарий, в котором при нажатии id 12a я хочу предупредить пользователя ввести номер и продолжить ввод число, пока они не набрали 5 стрелок. Где я неправ?Как это сделать, пока я не выйду из стрелок
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>
что именно проблема? – dreamweiver
Прежде всего, он не запускается, когда я нажимаю идентификатор. – NJeffries
его рабочий штраф здесь, https://jsfiddle.net/yd8tz438/ – dreamweiver