Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI 105 – Computer Fluency, Spring 2015

Similar presentations


Presentation on theme: "CSCI 105 – Computer Fluency, Spring 2015"— Presentation transcript:

1 CSCI 105 – Computer Fluency, Spring 2015
JavaScript Review CSCI 105 – Computer Fluency, Spring 2015

2 ALGORITHMS and FLOWCHARTS
A typical programming task can be divided into two phases: Problem solving phase produce an ordered sequence of steps that describe a solution to the problem this sequence of steps is called an algorithm Create a flowchart to document the program flow and logic Implementation phase implement the program in some programming language

3 Example Step 1: Input M1,M2,M3,M4 Step 2: GRADE  (M1+M2+M3+M4)/4
START Input M1,M2,M3,M4 GRADE(M1+M2+M3+M4)/4 IS GRADE < 50 PRINT “FAIL” STOP Y N Step 1: Input M1,M2,M3,M4 Step 2: GRADE  (M1+M2+M3+M4)/4 Step 3: if (GRADE < 50) then Print “FAIL” else Print “PASS” endif PRINT “PASS”

4 Knowledge –Terms and Concepts
1. Variables – hold a value, value can be numeric, text, true/false Declared at beginning of program and inside functions var dog; /* declared but undefined */ var dog = “Rover”; /* defined variable with initial assignment of a value */ Scope of variables: Global vs. Local 2. Expressions – evaluate to values, value can be numeric, text, true/false can be assignment such as dog = “Rover”; Math related such as total = price – (price * (discount / 100)); Text related such as salutation = “Dear “ + firstName + “,”; or conditional using if (dog == “rover”) And Logical (true/false) such as age < 14 or cost >=3.99

5 Knowledge – Program Flow
1. Top to Bottom 2. Loops repeat a section of code until a condition is met while (scoops > 0) { eatmore = “yes”; scoops = scoops -1; } 3. Functions are small routines that are called to accomplish a task and may or may not return a value function barkAtTheMoon( ) { bark = “Wooooooooooooooo”; alert (bark); }

6 Comprehension - Programming Method
Algorithm Flowchart (identifies the inputs, processes, and outputs) Implementation in a Programming language Variable declaration Code that accomplishes the algorithm Output the results

7 Battleship – Review (open in editor)

8 Rock Paper Scissors Game

9 Code – Rock-Paper-Scissors
var userChoice; var computerChoice; computerChoice = Math.random( ); /* this function returns a random value between 0 and 1 */ if (computerChoice >0 && computerChoice <= 0.34) { computerChoice = "rock"; } if (computerChoice >= 0.35 && computerChoice <= 0.67) { computerChoice = "paper"; } if (computerChoice >= 0.68 && computerChoice <= 0.99) { computerChoice = "scissors"; } userChoice = prompt("Do you choose rock, paper or scissors?");

10 Code – Rock-Paper-Scissors (better)
var userChoice = prompt("Do you choose rock, paper or scissors?"); var computerChoice = Math.random( ); if (computerChoice < 0.34) { computerChoice = "rock"; } else if(computerChoice <= 0.67) { computerChoice = "paper"; } else { computerChoice = "scissors"; }


Download ppt "CSCI 105 – Computer Fluency, Spring 2015"

Similar presentations


Ads by Google