MIS Coding

¡Supera tus tareas y exámenes ahora con Quizwiz!

Logical Operators

&& the AND operator: if the first expression and the second expression both evaluate to true. is true if and only all of its operands are true. ex. age > 17 && score < 70 ││ the OR operator: if either the first expression or second expression evaluate to true. ex. isNaN(rate) ││ rate < 0 ! the NOT operator: flips the value from false to true or true to false !isNaN(age) expressions evaluate to true or false.

Arithmetic operators

+ addition adds two operands - subtraction subtracts right operand from the left operand * multiplication multiplies two operands / divides right operand into the left operand. RESULT IS ALWAYS A FLOATING POINT NUMBER, meaning it can have decimal points % modulus divides right operand into the left operand and returns the remainder -21 %4 = 3 -21 /4 = -6

Concatenation operator: week 9, slide 39

+ concatenates two values += adds the result of the expression to the end of the variable javascript does not always do what you want when using the + operator, bc it is used to performing addition when dealing with numbers and concatenation when dealing with strings + Operator: var firstName = "Grace", lastName = "Hopper"; varfullName = lastName + ", " + firstName; // fullName is "Hopper, Grace" += Operator: var firstName = "Grace", lastName = "Hopper"; var fullName = lastName; //fullName is "Hopper" fullName += ", "; // fullName is "Hopper, " fullName += firstName; // fullName is "Hopper, Grace" x += y is the same as x = x + y

After 10 minutes, how many calories have you burned? After 30 minutes, how many total calories have you burned? If we change the initial value of i to 20 how many times does the function run and how many total calories are burned? If we change i <= 30 to i <= 40, how many times does the function run and how many total calories are burned?

1. Look at the alert alert('In' + i + 'minutes, you will have burned' + i* 4.5 + 'calories'); a. 10 * 4.5 = 45 calories b. 30 * 4.5 = 135 calories c. i = 10 changes to i = 20, so 20, 25, 30 is 3 and TOTAL calories still is equal to less than or equal to 30 so total calories is 135 d. 10 to 40 at intervals of 5 it runs seven times, TOTAL CALORIES is now equal to or less than 40 so it is 7, 180

What is your MPG if you have driven 320 miles and used 20 gallons of gas? (Analyze the Code)

1. Look at the calculation formula: MPG = Milesdriven/Gallonsofgasused 2. 320/20 = 16

Relational Operators:

== if the first expression evaluates to something that is equal to the second expression >= if the first expression evaluates to something greater or equal to the secon expression > if the first expression evaluates to something greater than second expression <= if the first expression evaluates to something lesser than or equal to the second expression < if the first expression evaluates to something less than the second expression != if the first expression evaluates to something not equal to the second expression

String

A JavaScript string stores a series of characters like "John Doe".

Boolean Conditional Statements

An "if" statement with a Boolean (true/false) expression: if(name != "") { ...what we do if the Boolean expression is true: alert ('Hello' + name); ...what we do if the Boolean expression is false: } else { alert('Hello stranger'); ***if the name does not equal blank (name not entered), alert hello + the name entered. ELSE anything else is entered ( a blank), alert hello stranger!***

Define Javascript:

JS is a programming language made up of english looking words arranged in a particular way to tell your browser to do something ex. listen to events like a mouse click and do something, modify HTML and CSS of your page after the page has loaded, make things move around the screen in interesting ways, create games that work in browsers, communicate data between the server and the browser, allow you to interact with a webcam, microphone, and other devices.

The order of operations

Javascript follows PEMDAS

Do...while loop

Looping condition is specified at the end (if false ---> end)

Evolution of the Digital Product Manager

Problem solvers, designers, creators, enablers

Software

Programs = Software = Apps

variables:

a name for a value/a place to hold a value. use var keyword followed by name you want to give your variable. ex. var myText; is a successfully declared variable. DECLARED. there is no value. initialize with = having one location to make a change that gets reflected everywhere. a major time saver

Loops

a sequence of instructions that is repeated until a certain condition is reached an operation is done, such as getting an item of data and changing it, and then some condition is checked such as whether a counter has reached a prescribed number good for code you need repeated multiple times

Functions:

a wrapper for code: groups statements together and makes code reusable. ALL FUNCTIONS HAVE A NAME, ARE PASSED ZERO OR MORE PIECES OF INFO, AND RETURN A VALUE (usually) function keyword (just the word function), followed by function name and opening and closing parentheses (), a bracket, and code function will run when called (invoked), then closing bracket a way to organize your code to make it easier to create, maintain, and reuse main program just does basic input/output. functions package up and perform the real work ex. of a function showDistance (speed, time) { alert(speed * time); } THIS FUNCTION HAS AN ARGUMENT BECAUSE THE () HAS WORDS IN IT. showDistance (10,5); showDistance (85, 1.5); etc. for calculating distance multiple times, you can avoid unnecessarily repeating code

+= (Concatenation)

adds the result of the expression to the end of the variables

Pair programming

agile software development technique in which two programmers work together at one station. the driver writes code while the observer or navigator reviews each line of code as it is typed in. they switch roles frequently.

If Else statements:

allow you to run code based on whether a condition is TRUE or FALSE. basic syntax: if (something is true) { do_something; {else} do_something_different; } ex. var safeToProceed = true; if (safeToProceed) { alert("You shall pass!"); } else { alert("You shall not pass!"); } THE SITE WOULD ALERT YOU "YOU SHALL PASS!" because the variable was initialized to True. var safeToProceed = false; IT WOULD ALERT YOU "YOU SHALL NOT PASS!" if (something_is_true) { do_something; } else { do_something_different; } ex. if (expression operator expression) { do_something; } else { do_something_different; } ex. if (age >= 18) { alert ("You may vote."); }

Variable names:

can be as short as one character or as long as you want. javascript is very lenient on what characters can go into a variable name. can be as short as one character or as long as you want can start with a letter, underscore, or the $ character CANNOT start with a number CANNOT have spaces outside of the first character, variables can be made up of any combo of letters, underscores, numbers, and $ characters. you can also mix and match lowercase and uppercase ex. var myText; var $; var r8; var_counter; car $field; varthisIsALongVariableName_butItCouldBeLonger; var_%abc; varOldSchoolNamingScheme;

Javascript with a little HTML

code gets access to the info typed on the form

+ (Concatenation)

concatenates two values

alert() is used to ex. alert(myText);

display information

The HTML <!DOCTYPE html>, <html> <body>

do not change

JavaScript is ___ driven

event driven. aka interactive. waits for the user to do something and then executes the code.

Javascript:

every piece of data that you provide or use is considered to contain a value

Flowcharts week 11 slide 14 and 15

ex. Hello World - understand the problem - develop the algorithm start --> prompt user for name ---> is the name not null ---> yes: display "hello" and their name ---> end OR ---> no ---> display "hello stranger" ---> end flows vertically downward

Conditional Expressions/Statements

expressions evaluate to true or false ex. Is the weather cold today? True: wear something warm. False: don't wear something warm. if it is not cold, you will wear something not warm. ex. last name == "Hopper" testScore == 10 firstName != "Grace" months != 0 testScore > 100 age < 18 distance >= limit stock <= reorder_point rate / 100 >= 0.1

3 Types of Loops

for loop, while loop, do...while loop (for and while most important)

wrong example of a function:

function getDistance(speed, time) { var distance = speed* time; return distance; if (speed < 0) { distance *= -1; } } --> WRONG BECAUSE ANYTHING AFTER "return" keyword will not be reached.

isNaN method: boolean expression

global method (available everywhere in your javascript code). global methods are also sometimes called functions. ex. myText instead of var myText is a global variable. syntax of global isNaN method: isNaN(expression) ex. isNaN ("Hopper") // returns true isNaN("123.45") // returns False

If else and else if statements

if ( position < 100) { alert (Do something!"); } else if ((position >= 100) && (position < 300)) { alert("Do something else!"); } else { alert("Do something even more different!"); if the first If statement is true, the code branches into the first alert (do something!). if the first if statement is false, the code evaluates the else if statement to see if the expressions in it evaluate to true or false. this repeats until your code reaches the end. or until an expression evaluates to true. if none of the statements have expressions that evalute to true, the code inside the Else block executes.

If else statements with multiple else clauses

if (isNaN(rate) ) { alert ("You did not provide a number for the rate."); } else if (rate < 0) { alert ("The rate may not be less than zero."); } else if (rate > 12) { alert ("The rate may not be greater than 12."); } else { alert ("The rate is: " + rate + "."); }

if only statements:

if statement without an else companion. if (weight> 500) { alert("No free shipping for you!"); } in this case, if expression evaluates as true, then great. if false, code skips over the alert and moves on to wherever it needs to go else.

Values

in javascript, every piece of data that you provide or used is considered to contain a a value. ex. alert(hello, world); has value of hello, world. have a specific representation under the covers provided by variables two key things you need to simplify life when working with them. must be able to: - easily identify them - reuse them without unnecessarily duplicating the value itself var keyword followed by the name you want to give your variable

declaration declaring vs initializing our variable to a value

initialize a variable to a default value with a equal sign (=). declaration is just var myText; initialization is var myText = "hello,world"; gives a variable value. can be changed whenever you want to whatever you want ex. var myText = "hello, world!"; ex. var myText = "hello, world!"; alert (myText) ex. var myText; myText = "hello, world!"; alert(myText);

prompt ()

lets you get input from the user always returns a string if the string looks like a number, javascript will convert the string to a number and do arithmetic if javascript is not converting strings to numbers as you expect, use parseInt() or parseFloat() to convert them

Strings

pieces of text wrap inside single or double quotation marks

Digital Economy, Geeks are

problem solvers, designers, creators, enablers

For loop

requires you to define the looping conditions up front. runs specified number of times for (var i = 0; i < 10; i++) { saySomething(); } start --> initialization ---> condition checking for true or false ---> if false, end ---> if true, increment/decrement --> statement

Return keyword in function

return keyword allows you to send data back to whatever called your function in the first place. it allows you to send data back to whatever called your function in the first place ex. var myDistance = getDistance (10,5); alert (myDistance); once your function hits the return keyword, it stops doing everything is it doing at that point, returns whatever value you specified to the caller, and exits the function only. it does not exit the program!! no code in your function after return will run. ex. function getDistance (speed, time) { var distance = speed * time; return distance; } instead of displaying an alert, we return the distance (as stored by the distance variable) to call the getDistance function, you just call it as part of initializing a variable: var myDistance = getDistance(10,5); alert(myDistance); when the getDistance function gets called, it gets evaluated and returns a numerical value that then becomes assigned to the myDistance variable. That is all there is to it.

CSS:

stands for Casading Style Sheets Describes how HTML elements are to be displayed on the screen: - inline: using style attributes in each HTML element - internal: using a <style> element in the <head> section - external: using an external CSS file saves a lot of work and can control the layout of multiple pages all at once

Three Steps of writing a program

understand the problem, develop the algorithm (the logical steps that solve the problem), write the code (the automated process)

the assignment operator

var myText = "hello, world!"; assignment operator is the = sign

Arguments in Functions

where your function call contains data that you pass into the function. function parameters are names listed in the function definition, while arguments are the real values passed to and received by the function. passing arguments: showDistance function has two arguments. speed, time ex. functionShowDistance (speed, time) { specify arguments to the function as part of the function call: ex. function showDistance(speed, time) { alert(speed*time); } showDistance(10,5) showDistance with specified values in parenthesis passes those values to the function (passes 10 and 5). ORDER MATTERS. (10, 5) means that 10 is the speed and 5 is the time.

Code that calculates the perimeter of a rectangle:

width = 4.25; length = 8.5; perimeter = (2* width) + (2* length) // (8.5 + 17) = 25.5

While loop

will run until its looping condition evaluates to being false. runs unspecified number of times. var count = 0; while (count < 10) { saySomething(); count ++; } start ---> condition checking ---> if false ---> if true statement and back to condition checking

HTML vs CSS vs JavaScript

HTML is all about displaying content. CSS is all about making content look good. JavaScript adds the interactivity. HTML adds structure, java adds functionality, CSS adds design elements. HTML means hyptertext markup language, CSS means cascading style sheets you need all 3 to make nifty looking sites.

T or F: A loop cannot start with a negative number ex. for (var i = -10; i <= 30; i=i+5)

FALSE.

Function call vs the function

Function Call: result of function that is code after the final }. the name the function you want to call (aka invoke) followed again by empty or filled parentheses. calling a function means telling the computer to run or execute that set of actions ex. showDistance(10,5); The Function: function showDistance(speed, time) { alert(speed * time); } ex. function sayHello () { alert("hello!"); } function call: sayHello();

What is wrong with the following statement: var 365days = prompt("How many days are in a year?");

VARIABLE NAMES CANNOT BEGIN WITH A NUMBER!!


Conjuntos de estudio relacionados

Fundamentals Quiz 3- Chapters 39,43,44,54

View Set

chapter 4 the external environment

View Set

11.2.2014, stats ch 7, probability

View Set

Chapter 6 Section 3 - Sedimentary Rock

View Set