javascript: more features b. ramamurthy 7/4/2014b. ramamurthy, cse651c1
Post on 29-Dec-2015
219 Views
Preview:
TRANSCRIPT
B. Ramamurthy, CSE651C 1
Javascript: More featuresB. Ramamurthy
7/4/2014
B. Ramamurthy, CSE651C 2
Review—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..
7/4/2014
B. Ramamurthy, CSE651C 3
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>
7/4/2014
B. Ramamurthy, CSE651C 4
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”);}
7/4/2014
B. Ramamurthy, CSE651C 5
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.
7/4/2014
B. Ramamurthy, CSE651C 6
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>
7/4/2014
B. Ramamurthy, CSE651C 7
JS file
window.onload = writeMessage(); function writeMessage(){ document.getElementById(helloMessage).innerHTML = “Hello, World!”;
}
// try this simple application
7/4/2014
B. Ramamurthy, CSE651C 8
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.
Complete Example
7/4/2014
B. Ramamurthy, CSE651C 9
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
7/4/2014
User Interface (UI) Design
B. Ramamurthy, CSE651C 10
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
7/4/2014
Design the functionality
B. Ramamurthy, CSE651C 11
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.
7/4/2014
Connecting the UI and JS functions
B. Ramamurthy, CSE651C 12
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.
7/4/2014
Applying the knowledge
B. Ramamurthy, CSE651C 13
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.
7/4/2014
Summary
B. Ramamurthy, CSE651C 14
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.
7/4/2014
Project Report
top related