Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 4: Javascript Basics Javascript is a scripting language based on pieces of C, C++, shell scripts, Pascal, Java, etc. Scripts – loosely typed C++

Similar presentations


Presentation on theme: "Lecture 4: Javascript Basics Javascript is a scripting language based on pieces of C, C++, shell scripts, Pascal, Java, etc. Scripts – loosely typed C++"— Presentation transcript:

1 Lecture 4: Javascript Basics Javascript is a scripting language based on pieces of C, C++, shell scripts, Pascal, Java, etc. Scripts – loosely typed C++ - object oriented ideas Pascal – some syntax elements C – much program syntax and semantics Java – no pointers Check this example out…. ProgramProgram

2 Example source code testing javascript This is a Javascript example. It adds two numbers and then pr var i=1 ; while( i < ) i+=1; window.alert("Fatal system error. Restart your computer now?");

3 Javascript basics Declaring variables: var keyword, typeless variables Basic I/O:document.writeln( ); window.alert( ); window.prompt( ); Type conversion:parseInt( );

4 Another example testing1.html var number1, n1,n2, number2, sum; number1=window.prompt("enter number 1", "0"); number2=window.prompt("enter number 2", "0"); n1 = parseInt(number1); n2= parseInt(number2); sum = n1 + n2; document.writeln(" Sum is "+sum+" ");

5 Control structures Boolean expressions for loops while statements if then else switch statements

6 Another example testing1.html var n1,n2,counter=0,i, piest = 0, // quadrant =new Array(4); sum=0; counter=window.prompt("Enter the number of desired samples:","100"); counter=parseInt(counter); for (i=1 ; i<=counter ; ++i) { n1=(Math.random()-0.5)*2; n2=(Math.random()-0.5)*2; if ((n1*n1)+(n2*n2) < 1) piest +=1; }; sum=(4*piest/counter); document.writeln("The estimate of pi is "+sum);


Download ppt "Lecture 4: Javascript Basics Javascript is a scripting language based on pieces of C, C++, shell scripts, Pascal, Java, etc. Scripts – loosely typed C++"

Similar presentations


Ads by Google