1 / 15

Javascript : More features

Javascript : More features. B. Ramamurthy. Review. Structure – Style -- Interaction. HTML provides structure CSS provides style Javascript (script) provides control for interaction and operations

inari
Download Presentation

Javascript : More features

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Javascript: More features B. Ramamurthy B. Ramamurthy, CSE651

  2. Review B. Ramamurthy, CSE651

  3. Structure – Style -- Interaction HTML provides structure CSS provides style Javascript (script) provides control for interaction and operations Inside js functions you can use any control structures such as if..else, for.., while and also any data structures such as array.. B. Ramamurthy, CSE651

  4. Simple JS (with embedded js) <!DOCTYPE html> <html> <head> <title> My first JavaScript </title> </head> <body> <h1> <script> document.write(“Hello, World!”); </script> </h1> </body> </html> B. Ramamurthy, CSE651

  5. JS functions A function consists of function followed by the name of the function The statement that make up the function go next within curly brackets Example: function saySomething() { alert(“ We are experimenting with JS”); } B. Ramamurthy, CSE651

  6. Moving JS to an external file Similar to how we separated style elements in css file, behavioral elements can be moved to an external js file. B. Ramamurthy, CSE651

  7. HTML with External File JS <!DOCTYPE html> <html> <head> <title> My second JavaScript </title> <script src=“script2.js”></script> </head> <body> <h1 id=“helloMessage”> </h1> </body> </html> B. Ramamurthy, CSE651

  8. JS file window.onload= writeMessage(); function writeMessage(){ document.getElementById(helloMessage).innerHTML = “Hello, World!”; } // try this simple application B. Ramamurthy, CSE651

  9. Complete Example B. Ramamurthy, CSE651 We will look at an example that has muitple section UI, image display, table layout, input/output from and to the UI. We will build the game “hangman” Even though this is a game, we can always make it into a serious game or an application that serves a particular need for your area. Once again this is only a template. Our approach is to look at the completed example and analyze the requirements, plan the UI layout and JS functions before jumping into coding them.

  10. User Interface (UI) Design B. Ramamurthy, CSE651 Top title section, bottom credit section, in between three vertical sections: one for the dynamically changing images of the hangman, middle section for the word and related buttons, right section for the UI keyboard of alphabets. Lets design this using <div> tag, <table> tag

  11. Design the functionality B. Ramamurthy, CSE651 This will be in javascript What are data structures/data needed? Define them in var section. What are functions we need? Initialize function that clears the board/word, picks a random word Another function for registering the current letter chosen Another for drawing the hangman or delivering the right image to the UI Somewhere here we need to keep track of the count of correct letters and decide win or lose and termination

  12. Connecting the UI and JS functions B. Ramamurthy, CSE651 We will incremental development checking each function as we proceed. To start with make sure UI and the js files connect using the alert(…) Then prototype each function’s logic and test it before integrating everything. Finally do an integration testing.

  13. Applying the knowledge B. Ramamurthy, CSE651 You can extend this application in many ways. Levels of playing with words of different lengths. A data base of different words can be added. Many levels of playing, continuous playing etc. There another exciting emerging area called “gamification/serious game” I am not going to discuss here… is a hot topic in the USA. Most of all you can use the design features and js features to apply these to one of your own work problems.

  14. Summary B. Ramamurthy, CSE651 We studied an important emerging platform in Javascript. It is just not used for design of web pages but for numerous applications such as mobile devices, communication formats(JSON), middleware (node.js), databases (mongodb) HTML5 offers a very path into designing mobils applications. There are many JS APIs and libraries that support rapid prototyping (Google MapAPI) Probably many of your automobile apps are made of these.

  15. Project Report B. Ramamurthy, CSE651 I would like you project report prepared using the html5 features (HTML + CSS + JS) we discussed. Any of your work projects can be done that way too! With live code and analyzers and all.

More Related