所以我完成了这个简单的任务,但我不明白为什么这不起作用?同一个人可以看到并告诉我吗?我看到问题是按钮没有调出功能,但为什么?
<html>
<head>
<title>Task count</title>
<script>
var over21 = 6.19;
var under21 = 5.19;
// Getting data from a user connecting variables with textboxes by ID
var age = document.getElementById('age');
var hours = document.getElementById('hours');
// function wich does all of the calculation
function magic(){
//cheking if he is under or over 21
if(age < 21){
alert("You will make " + (age*under21));
}else{
alert("You will make " + (age*over21));
};
};
// function that does everything and is connected to the button
function myFunction(){
// Validation checking that entered number is not more than 150
// And also if age is correct
if((hours < 150 && hours > 0) && (age < 150 && age > 12)){
magic();
}else{
alert("Wrong!");
};
};
</script>
</head>
<body>
<label>Enter your age.(12-150)</label>
<input type="text" class="textBox" id="age"><br>
<label>Enter how long will you work.(1-150)</label>
<input type="text" class="textBox" id="hours"><br>
<button onclick="myFunction()" >How much will i make ?</button>
</body>
</html>