Prompt box: Example 3 var num1 = prompt("Enter a number between 1 and 12","1") var promptstring = "What is " + num1 + " times 3?" var num2 = prompt(promptstring)

Slides:



Advertisements
Similar presentations
By Robert Lopshire.
Advertisements

Welcome to the Island! Student Information.
Nested If statements You can put if branches inside of if branches. Dog Collars var ans = prompt("Do you want to buy a dog collar??") if (ans.toLowerCase()
The Scientific Method.
1 PHP Statement Constructs Server Scripting. 5-2 Basic Statement All Statements end in a semicolon. Statements are delimited from the HTML code by enclosing.
Take a look around you! Colors are a part of your everyday life and make the world a fun place to live in! Lets learn some colors! Quiz Next Slide.
Use the above table to answer the questions about people’s favorite foods based on their age. If a person is chosen randomly, what is the probability they.
Operators, Expressions and Assignment Calculating Things...
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
Chapter 20 Thinking Big: Functions. Copyright © 2006 Pearson Addison-Wesley. All rights reserved Anatomy of a Function Functions are packages for.
The Elf’s Color Surprise!! A Guessing Game…click on the Elf to begin! By Lesley Dunham Odgers.
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
CIS101 Introduction to Computing Week 12 Spring 2004.
JavaScript Switch Statement. Switch JavaScript Switch Statement If you have a lot of conditions, you can use a switch statement instead of an if…elseif…
Mr. Wortzman. Tabs (Block Categories) Available Blocks Script Area Sprite Stage All sprites in this project.
The.
Dolch Vocabulary Words
Maths Test Tips. Place Value Remember where the digits are and what they are worth. Remember the names of the place value columns. The decimal point never.
An outcome is a possible result An event is a specific outcome Random means all outcomes are equally likely to occur or happen. random = fair A favorable.
Python.
220 Dolch Words.
7 th Grade Chapter 11 Displaying and Analyzing Data Chapter 12 Using Probability.
Adding JavaScript (<script tag>)
Created by Verna C. Rentsch and Joyce Cooling Nelson School
CONFIDENTIAL 1 Algebra1 Theoretical Probability. CONFIDENTIAL 2 Warm Up 1) choosing a heart. 2) choosing a heart or a diamond. An experiment consists.
Write down your choice of 5 different numbers between 1 and 36 Three ways to win. –In any order match: All 5 4 out of 5 3 out of 5 –Prize: Giant Book.
Probability Distributions
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
Dolch Vocabulary Words
The Grammar of JavaScript.  Each line of a script is a statement  An instruction that JavaScript can evaluate (make sense of)  Ends with a semicolon;
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
BLT # go help look at run.
The. to and a I you it in said for up look.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
The Colors Of Winter By Nancy Stewart. My winter coat is blue,
Grade 8 Computers Mr. McDowell. Scientific Method  The Scientific Method is an organized way of figuring something out. There are usually six parts…
Algorithms Writing instructions in the order they should execute.
Counter Probabilities Teacher's Notes Topic: Probability
List one thing that has a probability of 0?. agenda 1) notes on probability 2) lesson 1 example 1, 2 Exercise 5-8 Problem set 1-3 3)start lesson 3.
Decision Structures and Boolean Variables. Sequence Structures Thus far, we’ve been programming “sequence structures” Thus far, we’ve been programming.
Control Structures, Blocks and Compound Statements A good programming language allows you to control the flow of your program in three ways: - execute.
Claim 1 Smarter Balanced Sample Items Grade 7 - Target I
Dolch 220 Sharks! a is it am to an red up.
How to Square Root By: Destiny and Madelyn When trying to find the square root of 46 first you find the closest number that can evenly.
Pre-Algebra 9-7 Independent and Dependent Events Learn to find the probabilities of independent and dependent events.
First, write the unknown word on the line provided and include a page or paragraph reference. Second, write the complete sentence that contains the unknown.
Learn to code- JavaScript. Prt 1. TUTOR: DRKALMENIUS.
Computer Science I: Understand how to evaluate expressions with DIV and MOD Random Numbers Reading random code Writing random code Odds/evens/…
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 4: Making Decisions 1.
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
HTML HTML stands for Hyper Text Markup Language. HTML is used in making the base of a Website You can just use an online website maker like weebly.com.
Makeup By. lolpretty. Makeup Makeup is a girl’s love. So really every girl should love makeup adore makeup want to wear it 24/7.I know I do. I’m a girly.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #003 (February 14, 2015)
Conditionals.
The Law of Averages. What does the law of average say? We know that, from the definition of probability, in the long run the frequency of some event will.
Adding JavaScript ( ) JavaScript Guidelines document.write(" Hello World! ") Link Note: Try this without the tag.
Functions Wouldn’t it be nice to be able to bring up a new animal and paragraph without having to reload the page each time? We can! We can place the.
A. and away big blue can come down find for.
Loops Brent M. Dingle Texas A&M University Chapter 6 – Section 6.3 Multiway Branches (and some from Mastering Turbo Pascal 5.5, 3 rd Edition by Tom Swan)
11 Making Decisions in a Program Session 2.3. Session Overview  Introduce the idea of an algorithm  Show how a program can make logical decisions based.
Examples: JavaScript:
Starburst Activity notebook page 33.
Javascript Game Assessment
T. Jumana Abu Shmais – AOU - Riyadh
Probability Vocabulary:
What Color is it?.
Claim 1 Smarter Balanced Sample Items Grade 7 - Target I
This shows running the first guess number program which only allows one guess - I show the correct answer for testing purposes.
Presentation transcript:

Prompt box: Example 3 var num1 = prompt("Enter a number between 1 and 12","1") var promptstring = "What is " + num1 + " times 3?" var num2 = prompt(promptstring) document.write(" You think " + num1 + " times 3 is " + num2 + " ") link

Operators (What we can do with numbers) Operator y = 5 DescriptionExampleResult + Additionx=y+2x=7 - Subtractionx=y-2x=3 * Multiplicationx=y*2x=10 / Divisionx=y/2x=2.5 % Modulus (division remainder) x=y%2x=1

Prompt box: Example 3 var num1 = parseInt(prompt("Enter a number","1")) var num2 = parseInt(prompt("Enter a second number","1")) document.write(" Fun with numbers ") document.write(" ") var z = num1 + num2 document.write(num1 + " + " + num2 + " = " + z) document.write(" ") z = num1 - num2 document.write(num1 + " - " + num2 + " = " + z) document.write(" ") z = num1 * num2 document.write(num1 + " * " + num2 + " = " + z) document.write(" ") z = num1 / num2 document.write(num1 + " / " + num2 + " = " + z) document.write(" ") z = num1 %num2 document.write(num1 + " % " + num2 + " = " + z) document.write(" ") link

Conditional: If branches var answer = prompt("Do you like puppies?") if (answer == "yes") { document.write(" Me too! I love puppies, especially puppy bellies! ") } link

Conditional: If /else branches var age = parseInt(prompt("What is your age?")) if (age >= 21) { document.write(" Woo Woo. You're over " + age + " so you can drink legally. ") } else { document.write(" You're under " + age + " so don't even try drinking alcohol. ") } link

Comparisons: OperatorEnglishExampleResult ==Equal Tox == yfalse !=Not Equal Tox != ytrue <Less Thanx < ytrue >Greater Thanx > yfalse <= Less Than or Equal To x <= yTrue >= Greater Than or Equal To x >= yFalse  Check the relationship between values.  Note: a double equal sign (==) compares two values.  Comparison operators evaluate to either true or false. x = 3 y = 7

If – branching: var answer = prompt("what is your favorite color?") if (answer == "red") {document.write(" You are outgoing, aggressive, vigorous and impulsive! ") } else if (answer == "yellow") {document.write(" You are mentally adventurous, searching for novelty and self-fulfillment ") } else if (answer == "green") {document.write(" You are frank, community-minded, fairly sociable but prefer peace ") } else if (answer == "blue") {document.write(" You are soft, soothing, compassionate and caring ") } else if (answer == "purple") {document.write(" You are highly individual, witty and sensitive, with a strong desire to be unique ") } else if (answer == "orange") {document.write(" You are flamboyant and fun-loving and like a lively social life ") } document.write(" Thanks for playing! ")

More branching Calculate Your Grade var tests = parseInt(prompt("Exam grade?")) var labs = parseInt(prompt("Lab grade?")) var total = tests + labs / 100 if (total >= 90) {document.write(" You get an 'A' ") } else if (total >= 80) {document.write(" You get a 'B' ") } else if (total >= 70) {document.write(" You get a 'C' ") } else if (total >= 60) {document.write(" You get a 'D' ") } else {document.write(" You fail. ") } document.write(" Have a nice summer. ") link

If branching Do you need a coat in Europe? var ctemp = parseInt(prompt("What is the temperature (in Celsius?")) var ftemp = (9/5) * ctemp + 32 document.write(" The temp is " + ftemp + " ") if (ftemp > 20) {document.write(" You'll need a coat and hat ") } else if (ftemp > 45) {document.write(" You'll need a light coat ") } else if (total >60) {document.write(" You'll need a sweater ") } else if (total > 70) {document.write(" You're good without a coat ") } document.write(" Have fun!. ") link

Random Numbers JavaScript allows us to generate random numbers within a range of numbers using: randnum = Math.floor(Math.random() * range) What this does: It generates a random number between 0 and range and puts that random number in randnum

Breaking it down var randnum = Math.floor(Math.random() * 9) Math.random() generates a random number between 0 and 1 (e.g., 0.4). This number is multiplied by the range: Math.random() * 9 gives us 3.6 Math.floor(3.6) rounds down to the nearest integer. or 3 Finally, you need a variable to put all this in. I called my variable randnum, so in essence, var randnum = 3 What if you wanted a random number between 0 and 10, what would you do? What if you wanted a random number between 3 and 10? What if Math.random() generated.7? what would randnum hold?

Changing Color (Randomly) Page Colors: var randcolor = Math.floor(Math.random() * 3) if (randcolor == 0) {document.write(" This is blue ") } else if (randcolor == 1) {document.write(" This is red ") } else if (randcolor == 2) {document.write(" This is green ") } link

Using Random numbers: Heads or Tails? var ans = prompt("Heads or Tails?") if (ans == "Heads") {var numans = 0 } else if (ans == "Tails") {var numans = 1 } var compguess = Math.floor(Math.random() * 2) if (compguess == 0) {var compans = "Heads" } else {var compans = "Tails" } if (numans == compguess) {document.write(" You guessed correctly! You both guessed " + ans + "! ") } else {document.write(" You guessed incorrectly. You guessed " + ans + " and the computer guessed " + compans + ". ") } document.write(" Have fun!. ") link

Magic 8 Ball Magic 8 Ball Ask your question and the magic 8 ball will predict your answer! var ans = prompt("What do you wish to ask the magic 8 ball?") var randnum = Math.floor(Math.random() * 8) if (randnum == 0) {document.write(" There is no chance this will happen. ") } else if (randnum == 1) {document.write(" It is highly unlikely! ") } else if (randnum == 2) {document.write(" Probably not, but you never know. ") } else if (randnum == 3) {document.write(" Maybe. Maybe not. ") } else if (randnum == 4) {document.write(" This may happen if you are lucky. ") } else if (randnum == 5) {document.write(" Your chances are good. ") } else if (randnum == 6) {document.write(" This will almost certainly happen. ") } else if (randnum == 7) {document.write(" Definitely. ") } document.write(" Thank you for consulting the magic 8 ball! ") link

My Nike App Nike App var ans = prompt("How far did you run?") if (ans >= 6) {var x = Math.floor(Math.random() * 3) if (x == 0) {document.write(" Way to go with the long distances! ") } else if (x == 1) {document.write(" You're showing strong endurance! ") } else if (x == 2) {document.write(" Those distances are impressive! Keep it up! ") } else { var y = Math.floor(Math.random() * 4) if (y == 0) {document.write(" Those short runs help you build for the longer ones! ") } else if (y == 1) {document.write(" Good hustle! ") } else if (y == 2) {document.write(" Even short runs are better than sitting on the couch! ") } else if (y == 3) {document.write(" Keep running! That's what counts! ") } document.write(" Thank you for consulting the magic 8 ball! ") link