









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Professor: Padua-Perez; Class: INTRO INFO TECHNOLOGY; Subject: Computer Science; University: University of Maryland; Term: Fall 2006;
Typology: Study notes
1 / 15
This page cannot be seen from the preview
Don't miss anything!










statement // executed if expression is true ^ Second Form^ if (expression)
statement1 // executed if expression is trueelsestatement2 // executed if expression is false ^ If you want to execute more than one statement then use a set of { } toenclose the statements ^ Example
(See Example1.html)
JavaScript (Combination of Statements) ^ You can combine if, while and do while statements inseveral ways^ ^ You can have an several nested if statements^ ^ You can have if statements within while statements^ ^ You can have while statements within if ^ Example
Designing Solutions Using Pseudocode ^ So far we have focus on the syntax and semantics of JavaScriptconstruct ^ As the complexity of problems increases you need a strategy fordesigning solutions to such problems. ^ Several alternatives exist to come up with a solution to a problem(which we can then turned into a computer program)^ 1.^ Flowchart:
Graphical representation of the solution, where symbols represent input/output operations, conditionals, anditeration statements. 2. Pseudocode:
English-like description of the set of steps required to solve a problem.
This is the alternative we want
to use.
It represents our design! ^ When you write pseudocode you focus on determining the stepsnecessary to solve a problem without worrying about JavaScriptlanguage syntax issues.
Pseudocode Example
entries = read()prev = read()i = 1valid = truewhile (i < entries && valid) {curr = read()if (curr < prev) {
valid = false;} prev = curri = i + 1 } print(“Sequence is:”)print(valid) ^ Run always a trace table to verify your pseudocode is correct ^ Could you implement the above code without actually knowing what it does??
Suggestions for Implementation ^ Make sure you have written pseudocode ^ Do not wait until the last minute
JavaScript (Cascaded If Statement Idiom) ^ You can combine if statements to handle different cases ^ This approach to organized if statements in order to handle different cases is calledthe Cascaded If Statement ^ Cascaded If statement general form^ If (expr1)// Statement is executed if expr1 is trueelse if (expr2)// Statement is executed if expr2 is trueelse if (expr3)// Statement is executed if expr3 is trueelse// If none of the above expressions is true ^ Notice it is not a JavaScript statement. ^ Once one of the cases is executed no other case will be executed ^ You can use { } to enclose more than one statement ^ Example
(See Example5.html)
JavaScript (Functions) ^ Function - An entity that completes a particular task for us. It cantakes values necessary to complete the particular task and it canreturn values. ^ Examples of JavaScript functions^ ^ document.writeln^ ^ Alert() ^ You can define your own functions. ^ Let’s see an example of a function that computes a letter gradebased on a numeric grade. ^ Example
(See Example6.html) ^ How is the function executed?^ ^ Arguments are passed to the function^ ^ The letter grade is computed^ ^ Result is returned via the
return
statement