Upload
varsha
View
32
Download
1
Embed Size (px)
DESCRIPTION
START. Note that the No to both questions results in the same processing. This means you can do a compound AND since either can be true. Set up variables. yrBirth > 1980. Does not Meet criteria. marStat = “M”. Does not Meet criteria. Meet criteria. All done. End. - PowerPoint PPT Presentation
Citation preview
START
Set up variables
yrBirth > 1980
marStat = “M”
Does not Meet criteria
Meet criteria
Does not Meet criteria
All done
End
Note that the No to bothquestions results in the sameprocessing. This means youcan do a compound AND sinceeither can be true..
<html><head><title>JavaScript guess number game</title></head><body><script type="text/javascript"> var theName = window.prompt("Enter your name",""); var yrBirth = parseInt(window.prompt("enter the year of birth",0)); var marStat = window.prompt("enter your marital status",""); if (yrBirth > 1980 && marStat == "M") { document.write(theName + " you meet the criteria <br>" ); } else { document.write(theName + " you do not meet the criteria <br>" ); }</script></body></html>
START
Set up variables
yrBirth > 1980
marStat = “M”
Not married
Meet criteria
yrBirth not >1980
All done
End
Note the No to the questions results in different processing.Therefore you cannot make it compound, you have to ask thequestions separately.
<html><head><title>JavaScript AND</title></head><body><script type="text/javascript"> var theName = window.prompt("Enter your name",""); var yrBirth = parseInt(window.prompt("enter the year of birth",0)); var marStat = window.prompt("enter your marital status",""); if (yrBirth > 1980) { if (marStat == "M") { document.write(theName + " you meet the criteria <br>" ); } else { document.write(theName + " you are not married <br>" ); } } else { document.write(theName + " you birth year is not > 1980 <br>" ); }document.write("All done!")</script></body></html>
START
Set up variables
theState = “MA”
theState = “RI”
You live intheState
You live intheState
All done
End
Note that the YES to bothquestions results in the sameprocessing. This means youcan do a compound OR since either can be true.
YN
YN
You do notlive in MA
Or RI
<html><head><title>JavaScript guess number game</title></head><body><script type="text/javascript"> var theName = window.prompt("Enter your name",""); var theState = window.prompt("enter the state",""); if (theState == "MA" || theState == "RI") { document.write(theName + " you live in " + theState, "<br>" ); } else { document.write(theName + " you do not live in MA or RI <br>" ); }</script></body></html>
START
Set up variables
theState = “MA”
theState = “RI”
You live inRI
You live inMA
All done
End
Note that the YES to each question results in different processing, therefore you cannot write this as a compound.
YN
YN
You do notlive in MA
Or RI
<html><head><title>JavaScript OR</title></head><body><script type="text/javascript"> var theName = window.prompt("Enter your name",""); var theState = window.prompt("enter the state",""); if (theState == "MA") { document.write(theName + " you live in MA <br>" ); } else { if (theState == "RI") { document.write(theName + " you live in RI <br>" ); } else { document.write(theName + " you do not live in MA or RI <br>" ); } } document.write("All done!");</script></body></html>
START
Set up variables
yrBirth > 1980
gender = “F”
Meet criteria
Does not Meet criteria
All done
End
Note that it does not matter whether you have a marStat or M or a gender of F, you get the message meet criteria and also that the does not meet the criteria message is also the same in all circumstances. ThisAllows you to do a compound.
marStat =“M”
Meet criteria
Does not Meet criteria
YN
YN
YN
<html><head><title>JavaScript AND</title></head><body><script type="text/javascript"> var theName = window.prompt("Enter your name",""); var yrBirth = parseInt(window.prompt("Enter the year of birth",0)); var marStat = window.prompt("Enter your marital status (M, S, W, D)",""); var gender = window.prompt("Enter your gender (M or F)",""); if (yrBirth > 1980 && (marStat == "M" || gender == "F")) { document.write(theName + " you meet the criteria <br>" ); } else { document.write(theName + " you do not meet the criteria <br>" ); } document.write("All done!");</script></body></html>
START
Set up variables
yrBirth > 1980
gender = “F”
Meet marital
Not on yrBirth
All done
End
Note that every processing or write has a different message so this cannot be compound.
marStat =“M”
Meet genderNot on maritalOr gender
YN
YN
YN
<html><head><title>JavaScript AND</title></head><body><script type="text/javascript"> var theName = window.prompt("Enter your name",""); var yrBirth = parseInt(window.prompt("Enter the year of birth",0)); var marStat = window.prompt("Enter your marital status (M, S, W, D)",""); var gender = window.prompt("Enter your gender (M or F)",""); if (yrBirth > 1980) { if (marStat == "M") { document.write(theName + " you meet the criteria because you are married <br>" ); } else { if (gender == "F") { document.write(theName + " you meet the criteria because you are female<br>" ); } else { document.write(theName + " you do not meet the criteria on marital or gender <br>" ); } } } else { document.write(theName + " you do not meet the criteria on year of birth <br>" ); } document.write("All done!");</script></body>
Now I want you to solve these problems. Draw the logic flowchart (or you can writePseudocode) and then write the JavaScript. This assignment must be passed in by all students.
Enter a student name, major and gpa. If the student is a CI major with a gpa > 3.6 write a message that says you qualify for honors. Otherwise write a message that says you do not qualify for honors.
Enter a student name, major, number of credits and gpa. If the major is CI and either the number of credits is greater than 45 or the gpa is greater than 2.5 write the message that says you are entering your last semester.
Enter a student name, year started and number of credits. If the year started is greater than 2008 or the number of credits is greater than 45 write check transcript.