More than a series of javascript

Source: Internet
Author: User
Tags arithmetic operators arrays

The first chapter of JavaScript introduction

1. Enter a JavaScript statement in the address bar

Javascript:Document.write ("Show text")

2. Embed JavaScript in an HTML document

<script language=javascript>
Document.bgcolor= "Blue."
</script>

Chapter II using Variables and arrays

1. Declaring variables

<script language=javascripe>
Var Answer1,answer2,answer3,answer4;
answer1=9;
answer2=2.5
answer3= "Milkey May"
Answer4=true
</script>

2. Using integer

<script language=javascript>
var decimalnum,hexadecimalnum,octalnum
Decimalnum=24
hexadecimalnum=0x24
octalnum=024
document.write ("Display decimal number:" + decimalnum+ "<br>")
document.write ("Display hexadecimal number:" + hexadecimalnum + "<br>")
document.write ("Show octal number:" + octalnum + "<br>")
</script>

3. Using floating point numbers

<script language=javascript>
var num1,num2,num3,num4
num1=1234567890000.0
Num2=5.14e23
num3=0.0000123456
Num4=6.0254e3-4
document.write ("Floating-point number 1:" +num1+ "<br>")
document.write ("Floating-point number 2:" +num2+ "<br>")
document.write ("Floating-point number 3:" +num3+ "<br>")
document.write ("Floating-point number 4:" +num4+ "<br>")
</script>

4. Using Boolean values

<script language=javascript>
var answer1,answer2
Answer1=true
Answer2=false
document.write ("Display Boolean 1:" +answer1+ "<br>")
document.write ("Display Boolean 2:" +answer2+ "<br>")
</script>

5. Using a String

<script language=javascript>
var str1,str2
str1= "FDSGDG DSFDSF"
Str2= "Wuhan Rtvu"
document.write ("Display string 1:" +str1+ "<br>")
document.write ("Display string 2:" +str2+ "<br>")
</script>

6. Determine variable type

<script>
var answer1,answer2,answer3,answer4
Answer1=9
answer2=2.5
Answer3= "Milky May"
Answer4=true
document.write ("The type of variable 1 is:" +typeof answer1 + "<br>")
document.write ("The type of variable 2 is:" +typeof answer2 + "<br>")
document.write ("The type of variable 3 is:" +typeof Answer3 + "<br>")
document.write ("The type of variable 4 is:" +typeof answer4 + "<br>")
</script>

7. Convert a string into a number

<script>
var str1= "in January"
var int1=parseint (STR1)
document.write ("str1 data type is:" +typeof str1+ "<br>")
document.write ("Int1 data type is:" +typeof int1+ "<br>")
</script>

8. Convert numbers to Strings

<script>
var int1=256
var str1= "" +int1
document.write ("str1 data type is:" +typeof str1+ "<br>")
document.write ("Int1 data type is:" +typeof int1+ "<br>")
</script>

9. Declaring an array

<script>
Array=new Array (5)
Array[0]=1
Array[1]=3
Array[2]=5
Array[3]=7
array[4]=11
document.write ("Array is:" +array[0]+ "" +array[1]+ "" +array[2]+ "" +array[3]+ "" +array[4])
</script>

10. Determine the number of array elements

<script>
Array=new Array (5)
Array[0]=1
Array[1]=3
Array[2]=5
Array[3]=7
array[4]=11
document.write ("Array is:" +array[0]+ "" +array[1]+ "" +array[2]+ "" +array[3]+ "" +array[4]+ "<br>")
document.write ("The number of elements of an array is" +array.length)
</script>

11. Convert an array to a string

<script>
Array=new Array ()
array[0]= "Dark"
array[1]= "Apple"
array[2]= "Nebula"
array[3]= "Water"
Str1=array.join ()
Str2=array.join ("")
document.write (str1+ "<br>")
document.write (STR2)
</script>

12. Sorting arrays

<script>
Array=new Array ()
array[0]= "Dark"
array[1]= "Apple"
array[2]= "Nebula"
array[3]= "Water"
Str1=array.sort ()
document.write (str1+ "<br>")
</script>

Chapter Three Creating an expression

1. Using Arithmetic operators

<script>
Var1=12
var2=10
Varadd=var1+var2
Varsub=var1-var2
Varmult=var1*var2
Vardiv=var1/var2
Varmod=var1%var2
document.write ("Data 1 is:" +var1+ "<br>")
document.write ("Data 2 is:" +var2+ "<br>")

Related Article

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.