1. Type conversion:
It is divided into automatic conversion and casting, which is generally used for casting.
other types are converted to integers:parseint();
other types convert to decimals:parsefloat();
determine if it is a valid number type:IsNaN();
is a number then returns false, not a number to return ture.
Example:
Need to put prompt in isNaN method
2. operators:
Mathematical Operators :+-*/% + +--;
Relational Operators := = ! = >= <= > <;
logical Operators :&& | | ! ;
Other operators :+ = = *=/=%= ? :;
3. statement:
It is generally divided into sequential, branching, and cyclic statements.
(1) Branch statement if:
If(judging condition)
{
statements that meet the criteria to be executed
}
Else
{
statements executed when a condition is not met
}
(2) loop for statement:
For( initial condition; cyclic condition; state change )
{
Loop Body
}
(3) problem type: exhaustive, iterative.
(4) Two keywords: break and continue.
(5) If you want to output the value of a parameter: the value of the output is "+a+" and "+b"
<script>
function Visible1 ()
{$ ("P"). hide ();};
</script>
<body>
<input type= "button" onclick = "visible1 ()" value = " dot here let the text disappear "/>
<p> I will disappear. </p>
$ ("Id1") is equivalent to document.getElementById ("Id1")
Five Exercises
1. Enter integers A and B, if A2+B2 is greater than 100, output a2+b2 hundred or more digits, otherwise 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/>
2. 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/>
3. 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/>
4. 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/>
5. Enter the age of 10 people from the console into the array, the age of 10 people to sum up
<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>
HTML operators, type conversions