Understanding Pseudocode for Problem Solving in JavaScript - Prof. Nelson Padua-Perez, Assignments of Computer Science

The concept of pseudocode as a design strategy for solving complex problems in javascript. Pseudocode is an english-like description of the steps required to solve a problem, focusing on determining the necessary steps without worrying about programming language syntax issues. An example of pseudocode for finding the minimum value and explains the constructs used in pseudocode, including input, output, assignments, repetition structures, and conditionals.

Typology: Assignments

Pre 2010

Uploaded on 07/30/2009

koofers-user-cf8
koofers-user-cf8 🇺🇸

10 documents

1 / 11

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Announcements
Instructor: Nelson Padua-Perez ([email protected])
No posting of code in the forum
Check class announcements daily
You must implement programming projects by yourself
1
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Understanding Pseudocode for Problem Solving in JavaScript - Prof. Nelson Padua-Perez and more Assignments Computer Science in PDF only on Docsity!

Announcements

 Instructor: Nelson Padua-Perez ([email protected])

 No posting of code in the forum

 Check class announcements daily

 You must implement programming projects by yourself

Designing Using Pseudocode

 So far we have focused on the syntax and semantics of JavaScript  As the complexity of problems increase you need a design strategy to solve such problems  Several alternatives exist to come up with a solution to a problem. A popular one is Pseudocode

Pseudocode: English-like description of the set of steps required to solve a problem

 When you write pseudocode you focus on determining the steps necessary to solve a problem without worrying about programming language syntax issues

Pseudocode Elements

 When writing pseudocode you need the following constructs:  Input  Output  Assignments  Repetition Structures  Conditionals  To help you with the design of pseudocode you can use the following syntax to represent the above constructs

Pseudocode Elements

Input variable = read() e.g., x = read()  Output print(variable) e.g., print(x)  Assignment x = e.g., x = 20, s = “Bob”  Repetition while (expression) { OR do { stmts stmts } } while (expression)

 Notice the above constructs look like JavaScript code but they are not JavaScript code

How Good Is Your Pseudocode

 Your code does not use language constructs that are particular to a programming language

 Anyone receiving the pseudocode will not need to ask you questions in order to transform the pseudocode into code (no matter what the target programming language is)

do while Statement

 do while statement – Allows repetition of a set of statements

Basic Form do { statement // executed as long as expression is true

} while (expression) ;

 Notice the semicolon after the expression in parenthesis  Executes the statement at least once  You don’t need the { } if you only need to execute one statement  Example: DoWhileNumbers.html  Example: DoWhile.html  Any type of statements (including do whiles) in a do while  When to use a do while?  When to use a while?

Creating a Bookmark in a Document

 Use name attribute to define the target

 Use to jump to location

Web Site Snapshot/Video

 Online Example: http://www.cs.umd.edu/class/spring2009/cmsc122/projects/p2/p2Description.html#Sample_Output

Coding Example

 Let’s write a program that reads a password and allows a maximum of two attempts

 We can expand the program to have a menu of options once the appropriate password has been provided

 Using “\n” to define menu entries