Function JS Practice

Source: Internet
Author: User

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> Untitled Document </title>

<body>
input integers A and B, if the A2+B2 is greater than 100, the output a2+b2 hundred or more digits, otherwise the output two number and <br/>
<input type= "text" id= "a"/><br/>
<input type= "text" id= "B"/><br/>
<input type= "button" value= "click" onclick= "Dianji ()"/>
<script>
function Dianji ()
{
var a = parseint (document.getElementById ("a"). Value);
var B = parseint (document.getElementById ("B"). value);
if (a*a+b*b>100)
{
alert (A*A+B*B);
}
Else
{
alert (A+B);
}
}
</script>

<br/>
<br/>

Enter a year to determine whether it is a leap year (which can be divisible by 4 but not divisible by 100). Century years can be divisible by 400 is a leap year) <br/>
<input type= "text" id= "Run"/><input type= "button" value= "Check if it is a leap year" onclick= "Check ()"/>
<script>
function Check ()
{
var a =parseint (document.getElementById ("Run"). Value);
if (a%4==0&&a%100!=0 | | a%400==0)
{
Alert ("You entered the year of Leap Years");
}
Else
{
Alert ("Not a leap year");
}
}
</script>

<br/>
<br/>

Standard Weight:
Men's weight = height -100±3
Lady 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 weight: <input type= "text" id= "Weight"/><br/>
<input type= "button" value= "Check 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 ("Light weight, eat more")
}
Else
{
Alert ("Overweight, more exercise")
}
}
else if (sex== "female")
{
var zhong = height-110-weight;
if (zhong<=3&&zhong>=-3)
{
Alert ("Standard weight")
}
else if (zhong>3)
{
Alert ("Light weight, eat more")
}
Else
{
Alert ("Overweight, more exercise")
}
}
Else
{
Alert ("Gender input is wrong!") ")
}
}
</script>
<br/>
<br/>

A game, the first 20 off is each of its own scores,
21-30 off, 10 points per pass.
31-40 off, 20 points per pass
41-49 off, 30 points per pass
50 off, it's 100 minutes.
Enter the number of levels you are now in and ask for the score you have now
<br/>
Please enter the number of levels that are now breaking: <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 ("You get the total score:" +sum)
}
Else
{
Alert ("Wrong input!") ")
}
}
</script>

<br/>
<br/>


Enter the age of 10 people from the console into the array, sum the ages of 10 people
<br/>
<p id= "pp" > Please enter a 1th person's age 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= "In the text box, enter the age of the" +biao+ "Individual:";
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 ("Age sum is:" +sum)
}
}
</script>
</body>

Function JS Practice

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.