JS practice questions

Input integers a and b, if a2+b2 is greater than 100, output a2+b2 with a number above hundreds, otherwise output the sum of the two numbers<br />

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
  <input type="text" id="a" /><br />
  <input type="text" id="b" /><br />
  <input type="button" value="点击" onclick="dianji()" />
</body>
<script>
function dianji() {
  var oA = parseInt(document.getElementById('a').value);
  var oB = parseInt(document.getElementById('b').value);
  if(oA*oA+oB*oB>100){
    alert(oA*oA+oB*oB);
  }else{
    alert(oA+oB);
  }
}
</script>
</html>

Enter a year to determine whether it is a leap year (years that are divisible by 4 but not divisible by 100. Century years that are divisible by 400 are leap years)<br />

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<input type="text" name="" id="run"><input type="button" id="check" value="检查是否是闰年" onclick="jiancha();">
</body>
<script>
function jiancha(argument) {
  var a = parseInt(document.getElementById('run').value);
  if(a%4==0&&a%100!=0 || a%400==0){
    alert(a+"是闰年");
  }else{
    alert(a+"不是闰年");
  }
}
</script>
</html>

show:

Input integers a and b, if a^2+b^2 is greater than 100, then output a^2+b^2 with more than one hundred digits, otherwise output the sum of the two numbers


to enter a year to determine whether it is a leap year (years that are divisible by 4 but not divisible by 100. Century years that are divisible by 400 are leap years) 


standard weight: Men's weight=height-100±3 Women's weight=height-110±3  Please enter gender: 



Please enter height:
Please enter your weight:
standard level, each level is 30 points//50 levels, 100 points//input the number of levels you have passed now,  please enter the number of levels you have passed now if you have the score: 


Enter the ages of 10 people from the console into an array, and sum the ages of the ten people 

Please enter the age of the first person in the text box:

 

<br />
<br />

Standard Weight:
Men's Weight=Height-100±
3Women's Weight=Height-110±3
<br />
Please enter gender:<input type="text" id="sex" /><br />
Please enter height:< input type="text" id="height" /><br />
Please enter the weight: <input type="text" id="weight" /><br />
<input type="button" value="check Whether the weight is standard" onclick="tizhong()" />
<script>
function tizhong(){
  var sex =document.getElementById("sex").value;
  var height =parseFloat(document.getElementById("height").value );
  var weight = parseFloat(document.getElementById("weight").value);
if(sex=="male")
{
var zhong = height-100-weight;
if(zhong<=3&&zhong>=-3)
{
alert("standard weight")
}
else if(zhong>3)
{
alert("underweight, eat more")
}
else
{
alert("Overweight, exercise more")
}
}
else if(sex=="Female")
{
var zhong = height-110-weight;
if(zhong<=3&&zhong>=-3)
{
alert( "standard weight")
}
else if(zhong>3)
{
alert("underweight, eat more")
}
else
{
alert("overweight, exercise more")
}
}
else
{
alert("gender input has wrong!")
}
}
</script>
<br />
<br />

//For a game, the first 20 levels are the score of each level,
//21-30 levels are 10 points for each level
//31-40 levels are 20 points for each level
//41-49 levels, each level is 20 points. The level is 30 points
//50 levels, 100 points
//Enter the number of levels you have passed now, and ask for the score you have now
<br />
Please enter the number of levels you have passed now:<input type="text" id ="game" /><input type="button" value="Calculate score" onclick="jisuan()" />
<script>
function jisuan()
{
var a = parseInt(document.getElementById("game"). value);
if(a>0&&a<=50)
{
var sum=0;
for(var i=1;i<=a;i++)
{
if(i<=20)
{
sum+=i;
}
else if(i <=30)
{
sum+=10;
}
else if(i<=40)
{
sum+=20;
}
else if(i<=49)
{
sum+=30;
}
else
{
sum+=100;
}
}
alert("The total score you got is: "+sum)
}
else
{
alert("Incorrect input!")
}
}
</script>

<br />
<br />


Enter the ages of 10 people from the console into an array, and sum the ages of the ten people.
<br />
<p id="pp">Please enter the age of the first person in the text box:</p>
<input type ="text" id="age" />
<input type="button" value="add" id="jia" onclick="jia()" />
<script>
var array =new Array();
var biao =1;
function jia()
{
var aa =document.getElementById("jia").value;
if(aa == "Add")
{
array[biao-1] = parseInt( document.getElementById("age"). value);
document.getElementById("age").value="";
biao++;
document.getElementById("pp").innerText="Please enter the age of the person "+biao+" in the text box: ";
if(biao==10)
{
document.getElementById("jia").value="Add and calculate";
}
}
else
{
array[9] = parseInt( document.getElementById("age").value);
var sum=0;
for(var i=0;i<10;i++)
{
sum+=array[i];
}
document.getElementById("jia").disabled="disabled";
alert("年龄总和是:"+sum)
}
}
</script>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325308012&siteId=291194637