Download WGU D278 Scripting & Programming Foundations – Course Notes Study Guide (Latest PDF) and more Exams Javascript programming in PDF only on Docsity!
Chapter 1: Introduction
Coral uses psudeo-code to help demonstrate real processes that occur in other
languages. Their flowchart shapes identify specific types of processes
Ovals = start/end , parallelagrams = input/output statements, rectangles = processes
Chapter 1 Introduction summary
This chapter's key points included:
- A program consists of instructions (aka statements) that execute one at a time, to get input, process data, and put output.
- A program uses variables to hold data, which may change ("vary").
- A flowchart depicts a program graphically, with a node for each statement.
- A program can output a variable's value, or a string literal consisting of characters (including a newline character).
- A program can contain comments, which are for humans only and ignored when the program runs.
- Most whitespace (regular spaces or newlines) is ignored by a program, but good practice uses whitespace in a consistent way.
- The information age is quite new in human history. Changes are rapid.
- Computers surround us and computer numbers and usage continue to grow.
- Inside a computer, all data (characters, numbers, and more) is represented as bits: 0's and 1's.
- Programming is largely about problem solving, namely creating a methodical solution to a given task.
- Careers in computing are numerous, highly-rated, and growing. Non- computing jobs may benefit from programming.
- Pseudocode is an informal textual representation of a program intended for easy human understanding.
Chapter 2: Variables/Assignments
variable is a named item, such as x or numPeople, used to hold a value
assignment statement assigns a variable with a value, such as x = 5
assignment statement contains the following :
(variable) = (expression)
Example: z = w + 2 → z represents the variable while w+2 represent the expression
= in this statement means “z is assigned with w plus 2”. It does not mean it is equal like in algebra
variable declaration declares a new variable, specifying the variable's name and type
integer – holds whole number values
**caution: follow codes statement order. Variables are made to change as they are a key function of programming. **
Identifier – a label created by a programmer for an item such as a function or variable
Must 1. Be a sequence of letters, underscores, and digits 2. Must start with a letter
Identifiers are case sensitive
Reserved words (aka pre-defined functions) – is a word that is part of the language
like integer, Get, or Put (for Coral) usually color coded when programming
precedence rules – similar to PEDMAS in arithmetic, dictate the order of operations;
In this case of something has equal preference than it is based on left-to-right rules. Modulo has equal precedence to division and multiplication.
floating-point number is a real number, like 98.6, 0.0001, or -666.
floating-point literal is a number with a fractional part, even if that fraction is 0, as in
1.0, 0.0, or 99.
Programming infinity decimals results in at least 5 digits after the decimal
point This is sometimes adjusted in code
Put myfloat to output with 3 decimal places
Another example of why Coral is weird: Coral does NOT produce an error when floating- point division by 0. It will instead point to infinity or -infinity depending on the signs
0 / 0 = “not a number” outputted as NotANumber
Under normal coding, parameters would have to be taken in code to correct for issues like dividing by zero.
Coral references the term function like with math. Functions are objects located within a programming language that perform an operation. When placed into code, they are known as function call. Functions normally appear in different colors to indicate that the name has a specific “function” in the code and cannot be used as a variable (as referenced in Ch 1 variables can be anything from x, y, Sugar, AgeNumber)
The output for this would give x = 15 while y = 10
- Coral contains word pseudo-code and often leaves key elements that need to normally be established when coding, out of their coding lines. Keep this in mind when translating
Chapter 2 Labs
The labs can be confusing and redundant. No programming would actually use so many lines just to write a sentence or two. It would end up running code thousands of pages.
Some people use the videos posted on Youtube, but they are also found on Panopto https://wgu.hosted.panopto.com/Panopto/Pages/Viewer.aspx?id=ceeec123-c633- 4ac7-92a3-aea000e5e521&query=D278%20lab
If you are unable to find a way to access directly, search on google for WGU Panopto then log in. search for videos via D278.
Note: My labs are here to post as reference for study and if you are having issues with the labs, please see the video as just putting in the answers does not help yourself or help you pass the course.
(code continued 2.21)
This lab, instead of stressing the priorities of left to right variable to expression on converting integers to floating number, it simply wanted us to create a lot of variables to make the output for the integer then the output for floating numbers.
Note: Make sure to designate all integers as floats
Chapter 2 Variable/Assignments summary
This chapter's key points included:
- A variable declaration declares a new variable, specifying the variable's name and type.
- An assignment statement assigns the variable on the left-side of the = with the current value of the right-side expression.
- An expression is a combination of items, like variables, literals, operators, and parentheses, that evaluates to a value.
- A name created by a programmer for an item like a variable or function is called an identifier, which must follow certain rules to be valid. Programmers typically follow identifier naming conventions that are defined by their company, team, teacher, etc.
- An expression is evaluated using precedence rules that follow the evaluation order of standard mathematics.
- Incremental development is the process of writing and and testing a small amount of code, then writing and testing a small amount more (an incremental amount), and so on.
- A variable declared as type float stores a floating-point number, which is a real number, like 98.6, 0.0001, or -666.667.
- A programmer should choose a variable's type based on the type of value held. Integer variables are typically used for values that are counted. Floating- point variables are typically used for values that are measured or when dealing with fractions of countable items, such as the average number of cars per household.
- Programming languages typically have built-in functions to perform common operations needed by programmers, such as performing mathematical operations like square root or raising a number to a power.
- A function is a list of statements executed by invoking the function's name, with such invoking known as a function call.
- Programming languages typically have built-in functions for generating random numbers. The integers generated by a random number generator are known as pseudo-random. "Pseudo" means "not actually, but having the appearance of". Internally, the RandomNumber() function has an equation to compute the next "random" integer from the previous one.
- When the operands of / are both integers, the operator performs integer division, which does not generate any fraction.
- For integer division, the second operand of / or % must never be 0, because division by 0 is mathematically undefined. A divide-by-zero error occurs at runtime if a divisor is 0, causing a program to terminate.
- A type conversion is a conversion of one data type to another, such as an integer to a float.
- zyFlowchart, and other programming languages, automatically performs several common conversions between integer and float types, and such automatic conversion is known as implicit conversion.
- If a programmer needs to explicitly convert an item's type, the programmer can use a type cast to converts value of one type to another type.
- The modulo operator (%) evaluates to the remainder of the division of two integer operands.
- A constant is a named value item that holds a value that cannot change. Constants are commonly used in programs to hold the value of mathematical constants or a value that should not change during the program's execution.
Chapter 3 Branches
Note: Difference between implicit and explicit. When ranges have no gaps then it is implicit otherwise it is explicit
Chapter 3 Branches Summary
This chapter's key points included:
- In a flowchart, a decision creates two branches, one for when the decision's expression is true (the if branch), another when false (the else branch).
- If-else branches have statements in each branch. An if branch has no statements in the else branch.
- If-elseif branches have cascaded decisions along the false branches. Only one true branch can execute.
- A branch can itself have a decision, known as nested branches.
- Multiple if branches can be created, which are independent, so more than one true branch can execute.
- Valid equality and relational operators are ==, !=, <, <=, >, >=.
- If-elseif branches are commonly used to detect ranges, with the lower end of the range implicit.
- Logical operators are: and, or, not.
- In an expression, operators are evaluated in a specific order based on precedence rules (just like in math).
- Because floating-point numbers aren't represented exactly, they shouldn't be compared for equality (using ==). Instead, they can be compared for "close enough".
- Branches in pseudocode use words like if, else, and elseif, and a branch's statements appear indented starting on a next line.
Chapter 4: Loops
Questions often ask what is the initiation expression or condition statement. These are two different ways of looking at statements (while statement on the left, and any loop on the right)