Full Transcript

JAVASCRIPT WHAT’S A SCRIPTING LANGUAGE?  A scripting language is a programming language that is interpreted. It is translated into machine code when the code is run, rather than beforehand. Scripting languages are often used for short scripts over full computer programs. JavaScript, Python, and Rub...

JAVASCRIPT WHAT’S A SCRIPTING LANGUAGE?  A scripting language is a programming language that is interpreted. It is translated into machine code when the code is run, rather than beforehand. Scripting languages are often used for short scripts over full computer programs. JavaScript, Python, and Ruby are all examples of scripting languages.  Scripting language (also known as scripting, or script) is a series of commands that are able to be executed without the need for compiling. While all scripting languages are programming languages, not all programming languages are scripting languages. PHP, Perl, and Python are common examples of scripting languages. JAVASCRIPT DEFINITION JavaScript is a cross-platform, object-oriented scripting language used to make webpages interactive (e.g., having complex animations, clickable buttons, popup menus, etc.). There are also more advanced server side versions of JavaScript such as Node. ▪ Key points ▪ Language developed by Netscape ▪ Primary purpose is for "client-end" processing of HTML documents ▪ JavaScript code is embedded within the html of a document ▪ An interpreter in the browser interprets the JavaScript code when appropriate ▪ Code typically allows for "preprocessing" of forms and can add "dynamic content" to a Web page JAVASCRIPT SYNTAX EXAMPLE 1 Text editor (notepad file) First JavaScript Example document.write("These lines are produced by"); document.write("the JavaScript program"); alert("Hey, JavaScript is fun!"); To write first application in JavaScript is all going to be written using NotePad. Open NotePad and save the resulting empty document in your user drive as Example 1.html. EXAMPLE 2 DECISIONS –IF...ELSE STATEMENT ▪ In computer programming, there may arise situations where you have to run a block of code among more than one alternatives. For example, assigning grades A, B or C based on marks obtained by a student. ▪ In such situations, you can use the JavaScript if...else statement to create a program that can make decisions. In JavaScript, there are three forms of the if...else statement. 1.if statement 2.if...else statement 3.if...else if...else statement JAVASCRIPT IF STATEMENT STATEMENT EXAMPLE 1 IF…ELSE STATEMENT You can use If….Else statement if you have to check two conditions and execute a different set of codes. EXAMPLE 1 IF…ELSE IF…ELSE STATEMENT EXAMPLE SWITCH – CASE EXAMPLE To print day name