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()

Slides:



Advertisements
Similar presentations
HTML Basics Customizing your site using the basics of HTML.
Advertisements

List 1 Dolch Phases.
function coffeeinfo() { document.getElementById('p3').innerHTML = "The word 'coffee' was.
Hypertext markup language.  Client asks for an html file  Server returns the html file  Client parses and displays it  This display is what most people.
document.getElementById Used to change anything in your document (web page) that has an id Then you can change different aspects of the element with that.
CS 330 Programming Languages 10 / 14 / 2008 Instructor: Michael Eckmann.
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…
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)
Review. What is wrong with the following function? imgArray = new Array() imgArray[0] = “mypic.jpg” imgArray[1] = “mypic2.jpg” imgArray[2] = “mypic3.jpg”
The.
Robbie’s Birthday Spending “Hi, my name is Robbie and I just turned 7 years old.” “For my birthday last week I got $22!” “Today, mommy is taking me to.
Adding JavaScript (<script tag>)
Loops Doing the same thing over and over and over and over and over and over…
INTRODUCTION TO CLIENT-SIDE WEB PROGRAMMING ACM 511 ACM 262 Course Notes.
Allies Kitten by: Sadie VanBuskirk. Copyright Copyright © By Sadie VanBuskirk All rights reserved Do anything you want with this book Printed in nova.
Amber Annett David Bell October 13 th, What will happen What is this business about personal web pages? Designated location of your own web page.
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
1 Essential HTML coding By Fadi Safieddine (Week 2)
Images (1) Three most popular formats – Graphics Interchange Format (GIF) – Joint Photographic Experts Group (JPEG) – Portable Network Graphics (PNG) –
CSS Class 7 Add JavaScript to your page Add event handlers Validate a form Open a new window Hide and show elements Swap images Debug JavaScript.
Images in HTML PowerPoint How images are used in HTML.
Manipulating the DOM CST 200 – JavaScript 3 –
Last week you should have had something that looked like this.
Unit 2, cont. September 12 More HTML. Attributes Some tags are modifiable with attributes This changes the way a tag behaves Modifying a tag requires.
1 JavaScript 1. 2 Java vs. JavaScript Java –Is a high level programming language –Is platform independent –Runs on a standardized virtual machine.
High Frequency Word Phrases
Topic: An Introduction to JavaScript - from Beginning JavaScript by Wilton (WROX)
High Frequency Word Phrases
Week 1 – Beginners Content McAfee & Big Fish Games CoderDojo.
Game var count = 0 var total = 0 function myfunc() { if (count < 50) {var basetime = 1000 document.getElementById('img1').src = "Images/gopher.jpg" document.getElementById('img1').style.position.
Adventure! By: Dayja Cade. Hi our fellow friends! My name is Conner the Dog, and my name is Felix the Kat. Today our adventure is to go on an Easter egg.
JavaScript Programming Unit #1: Introduction. What is Programming?
URails Meeting 004. Ruby Quiz Is the following statement accessing a variable or calling a method? profile.user_name Could be either. Calling a method.
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
Given the following code, what picture is displayed in the second image on the page when the first image is clicked on the first time? ___________________________.
Bike. are at can big cannot am book books.
CRE Programming Club - Class 2 Robert Eckstein and Robert Heard.
JavaScript Challenges Answers for challenges
HTML IMAGES. CONTENTS IMG Tag Alt Attribute Setting Width and Height Of An Image Summary Exercise.
 Scripts that execute in response to some event  User clicking on something  Script does NOT execute as part of page loading  DOM facilities like.
SetTimeout()  What if you want to automatically cycle through the pics?  So you don’t have to keep clicking the button to see the next pic  Use the.
Changing HTML Attributes each() function Anonymous Functions $(this) keyword.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
Assistant Professor,UCER Naini,Allahabad
Second Grade Dolch Words egreay. a and away big.
Link. setTimeout() What if you want to automatically cycle through the pics? So you don’t have to keep clicking the button to see the next pic Use the.
Dolch Word List By: Beth Terracina. Preprimmer a.
Introduction to Arrays. Learning Objectives By the end of this lecture, you should be able to: – Understand what an array is – Know how to create an array.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
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.
InnerHTML: This is a paragraph about Ted the cat What is the innerHTML of ‘cat’? zombies
Examples: JavaScript:
Just enough to get going!
Looping SetTimeout is a loop
Images in HTML PowerPoint How images are used in HTML
Web Design and Development
HTML Images CS 1150 Spring 2017.
HTML.
Putting Images on Your Web Page
Basic HTML and Embed Codes
Putting An Image on Your Web Page
HTML Images CS 1150 Fall 2016.
Pertemuan 1b
That detail is only sort of important That detail is only sort of important. What is important is that you have all of these HTML elements floating.
Basics of HTML Lesson 1: Basic HTML.
Lesson 7 Graphics.
he had to she said that to the but she said.
Images in HTML PowerPoint How images are used in HTML
Presentation transcript:

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() == "yes") {var collarsize = prompt("small, medium, or large?") if (collarsize.toLowerCase() == "large") {document.write(" Your total is 17 dollars ") } else if (collarsize.toLowerCase() == "medium") {document.write(" Your total is 13 dollars ") } else if (collarsize.toLowerCase() == "small") {document.write(" Your total is 8 dollars ") } else { document.write(" Sorry I couldn't be of more help. ") } document.write(" Shop again soon! ") 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! ") } link

More Nested Ifs Lousy Nike App var ans = prompt("How far did you run?") if (ans >= 6) { if (ans > 10) {document.write(" Wow! You really went far! ") } else if (ans > 7) {document.write(" That's a pretty impressive distance! ") } else if (ans < 4 ) {document.write(" Short runs build muscle! ") } else { if (ans > 10) {document.write(" Awesome run! ") } else if (ans < 2) {document.write(" You burnt calories! ") } else {document.write(" Keep running! ") } What if you ran 11 miles? 7 miles? 3 miles? link

nested if exercise How much vitamin D? Are you male or female? For males: if you get less than 1 hour of sun a day, take 1000 iu a day, otherwise you don’t need to take any For females: If you’re 50 or over, you should take 2000 ius a day If you’re under 50 and get less than 1 hour a day of sun, you should take 1500 ius a day Otherwise you should take 500 ius a day.

Arrays: Storing more than one thing We use variables to hold single values: var num = 3 var ans = “yes” var color = “blue” There are times when we want to keep a set of things together: Like maybe a set of colors, or phrases, or products, or even pictures We will use an array for that!

Creating an array Array is a variable with more than one space in which to put something E.g., To create the array (to let the browser know we want to have an array available to use), we must first define it: var arrayHolder = new Array(); Now we have an array called arrayHolder, and it is empty we haven’t put anything in it yet ”

Putting values in the array To put something in the array, we use the array’s name and the number of the cubbyhole: arrayHolder[0] = “hello” arrayHolder[1] = “howdie” arrayHolder[2] = “greetings” arrayHolder[3] = “hey there” arrayHolder[4] = “hi” arrayHolder[5] = “wassup” Now the array arrayHolder at space 2 will hold “greetings” “hello””howdie”“greetings”“hey there”“hi”“wassup”

Making and using an array var myArray = new Array() myArray[0] = "hey" myArray[1] = "hi" myArray[2] = "wassup" myArray[3] = "greetings" myArray[4] = "howdie" document.write(" " + myArray[3] + " ")

What about this? Hello var myArray = new Array() myArray[0] = "hey" myArray[1] = "hi" myArray[2] = "wassup" myArray[3] = "greetings" myArray[4] = "howdie" var ans = prompt("Pick your greeting (0 - 4)") document.write(" " + myArray[ans] + " ") link

How about this? var myArray = new Array() myArray[0] = "hey" myArray[1] = "hi" myArray[2] = "wassup" myArray[3] = "greetings" myArray[4] = "howdie“ var num = Math.floor(Math.random() * 5) document.write(" " + myArray[num] + " ")

What does this do? var EngArr = new Array() EngArr[0] = "dog" EngArr[1] = "cat" EngArr[2] = "hello" EngArr[3] = "Thank you" EngArr[4] = "bunny" var FrenchArr = new Array() FrenchArr[0] = "chien" FrenchArr[1] = "chat" FrenchArr[2] = "bonjour" FrenchArr[3] = "merci" FrenchArr[4] = "lapin“ var ans = prompt("Pick a number (0 - 4)") var frenchans = prompt("What is the French translation of " + EngArr[ans] + "?") if (frenchans.toLowerCase() == FrenchArr[ans]) {document.write(" You're right! ") } else {document.write(" Sorry. You're no good at this. ") } link

What about this one? var PicArr = new Array() PicArr[0] = "cute1.jpg" PicArr[1] = "cute2.jpg" PicArr[2] = "cute3.jpg" PicArr[3] = "cute4.jpg" PicArr[4] = "cute5.jpg" var NameArr = new Array() NameArr[0] = "lion cubs" NameArr[1] = "hedgehogs" NameArr[2] = "otter pup" NameArr[3] = "kitten" NameArr[4] = "panda babies“ var num = Math.floor(Math.random() * 5) document.write(" ") document.write(" " + NameArr[num] + " ") link

Changing existing image or element document.getElementById() Can be used to change any tag with an id on your web page Remember, we gave different elements unique ids We can use those ids to change something about the element with that id Images on your web page: We can use the getElementById() to change the: src width height alt

getElementById() Hello <img src = "ball.jpg" width = "100" height = "100" alt = "a ball picture" id = "ball1"> var x = parseInt(prompt("What size should the ball's width be?")) document.getElementById("ball1").width = x link

What does this do? Hello <img src = "ball.jpg" width = "100" height = "100" alt = "a ball picture" id = "ball1"> var x = Math.floor(Math.random()*300) var y = Math.floor(Math.random()*300) document.getElementById("ball1").width = x document.getElementById("ball1").height = y link

What does this do? Hello <img src = "kittenasleep.jpg" width = "200" height = "200" alt = "a picture" id = "pic1"> var ans = prompt("Want to see something else?") if (ans.toLowerCase() == "yes") {document.getElementById("pic1").src = "kittybelly.jpg" } link