Introduction to Programming and JavaScript. Programming.
-
Upload
rhoda-cameron -
Category
Documents
-
view
215 -
download
0
Transcript of Introduction to Programming and JavaScript. Programming.
![Page 1: Introduction to Programming and JavaScript. Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082713/5697c02c1a28abf838cd907e/html5/thumbnails/1.jpg)
Introduction to Programming and JavaScript
![Page 2: Introduction to Programming and JavaScript. Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082713/5697c02c1a28abf838cd907e/html5/thumbnails/2.jpg)
Programming
![Page 3: Introduction to Programming and JavaScript. Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082713/5697c02c1a28abf838cd907e/html5/thumbnails/3.jpg)
What is a Program?
Instructions
ComputerUnderstands
Perform Task
![Page 4: Introduction to Programming and JavaScript. Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082713/5697c02c1a28abf838cd907e/html5/thumbnails/4.jpg)
What is Programming?
Requirements
Process
Code
Test
![Page 5: Introduction to Programming and JavaScript. Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082713/5697c02c1a28abf838cd907e/html5/thumbnails/5.jpg)
Types of Programs
OS/Hardware
ApplicationRuntimeModule
Script Processor
Interpreter
Byte Code
Executable(Machine Code)
Compiler
Compiler
Macro/Script
Applet
Executable
Program
Interpreted Program
SourceCode
SourceCode
SourceCode
SourceCode
Virtual Machi
ne
![Page 6: Introduction to Programming and JavaScript. Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082713/5697c02c1a28abf838cd907e/html5/thumbnails/6.jpg)
Object Oriented Programs
OOP
![Page 7: Introduction to Programming and JavaScript. Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082713/5697c02c1a28abf838cd907e/html5/thumbnails/7.jpg)
Basics of Objects
InterfacePrint this,
Current ink level?,Out of paper!, …
?Properties
Ink level,Paper in tray,
…
MethodsPrint page, Eject page,
…
![Page 8: Introduction to Programming and JavaScript. Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082713/5697c02c1a28abf838cd907e/html5/thumbnails/8.jpg)
Algorithms and Programs
Algorithm ProgramEffective
Efficient
Reliable
Understandable
Maintainable
![Page 9: Introduction to Programming and JavaScript. Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082713/5697c02c1a28abf838cd907e/html5/thumbnails/9.jpg)
Control Structures
Sequence Conditional
Open File
Format File
Print File
Save File
Close File
Get Section Status
Section Full?
RegisterStudent
RejectRegistration
No Yes
![Page 10: Introduction to Programming and JavaScript. Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082713/5697c02c1a28abf838cd907e/html5/thumbnails/10.jpg)
Control Structures
Loop
Open Student File
Get Student Record
Print Grade Report
Students Left?
Close Student File
Yes
No
Transfer (GoTo)
Open File
Print File
Format File
Close File
Save File
Spaghetti Code!
![Page 11: Introduction to Programming and JavaScript. Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082713/5697c02c1a28abf838cd907e/html5/thumbnails/11.jpg)
JavaScript
<script type="text/javascript">function shutdown(){
alert('Shutting Down Internet.')}</script>
![Page 12: Introduction to Programming and JavaScript. Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082713/5697c02c1a28abf838cd907e/html5/thumbnails/12.jpg)
JavaScript
• A programming language.
• Executed as a script.
• Object oriented.
• Extensive document object model (DOM).
• No file read/write access (except cookies).
<script type="text/javascript">function shutdown(){
alert('Shutting Down Internet.')}</script>
![Page 13: Introduction to Programming and JavaScript. Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082713/5697c02c1a28abf838cd907e/html5/thumbnails/13.jpg)
<script>
<script type=“text/javascript”>
</script>
Program code written in JavaScript. JavaScript comments. NO HTML!
![Page 14: Introduction to Programming and JavaScript. Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082713/5697c02c1a28abf838cd907e/html5/thumbnails/14.jpg)
Script Locations<html>
</html>
<head>
</head>
<body>
</body>
<script> … </script>Script is reusable.“Call” script to execute it.
<script> … </script>Script is executed as the browser displays the web page.
ExternalScriptFile
![Page 15: Introduction to Programming and JavaScript. Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082713/5697c02c1a28abf838cd907e/html5/thumbnails/15.jpg)
<noscript>
• At start of body.
• Alert users without JavaScript support.
![Page 16: Introduction to Programming and JavaScript. Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082713/5697c02c1a28abf838cd907e/html5/thumbnails/16.jpg)
Objects, Events, & Event Handlers
Object
Click button= Click Event
<body><h1>Shutdown Internet?</h1><input type="button"
value="Shutdown Internet" onclick="shutdown()" />
</body>
<head><script type="text/javascript">function shutdown(){
alert('Shutting Down Internet.')}</script></head>
![Page 17: Introduction to Programming and JavaScript. Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082713/5697c02c1a28abf838cd907e/html5/thumbnails/17.jpg)
Comments Please!JavaScript code … // comment
JavaScript code … /* comment */
JavaScript code … /* commentcontinues on this lineand on this line */
JavaScript code … /* comment starts on this lineand continues on this lineand on this line */
![Page 18: Introduction to Programming and JavaScript. Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082713/5697c02c1a28abf838cd907e/html5/thumbnails/18.jpg)
Bugs – Syntax Errors<html><head><script type="text/javascript">function shutdown(){
do alert('Shutting Down Internet.')}</script></head><body><h1>Shutdown Internet?</h1><input type="button" value="Shutdown Internet" onclick="shutdown()" /></body></html>
line 8
error is here!
![Page 19: Introduction to Programming and JavaScript. Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082713/5697c02c1a28abf838cd907e/html5/thumbnails/19.jpg)
Bugs – Runtime Errors<html><head><script type="text/javascript">function shutdown(){
alert('Shutting Down Internet.')}</script></head><body><h1>Shutdown Internet?</h1><input type="button"
value="Shutdown Internet" onclick="do_onclick()" />
</body></html>
![Page 20: Introduction to Programming and JavaScript. Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082713/5697c02c1a28abf838cd907e/html5/thumbnails/20.jpg)
Bugs – Logic Errors
function compute_gross_pay(hours, rate){
Gross = hours + rate
return Gross
}