130 likes | 332 Views
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. <html>
E N D
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
<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 Note the No to the questions results in different processing. Therefore you cannot make it compound, you have to ask the questions separately. Set up variables yrBirth > 1980 yrBirth not > 1980 marStat = “M” Not married Meet criteria All done End
<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 Note that the YES to both questions results in the same processing. This means you can do a compound OR since either can be true. Set up variables theState = “MA” N Y theState = “RI” You live in theState N Y You live in theState You do not live in MA Or RI All done End
<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 Note that the YES to each question results in different processing, therefore you cannot write this as a compound. Set up variables theState = “MA” N Y theState = “RI” You live in MA N Y You live in RI You do not live in MA Or RI All done End
<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 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. This Allows you to do a compound. Set up variables yrBirth > 1980 N Y Does not Meet criteria marStat = “M” N Y gender = “F” Meet criteria N Y Does not Meet criteria Meet criteria All done End
<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 Note that every processing or write has a different message so this cannot be compound. Set up variables yrBirth > 1980 N Y Not on yrBirth marStat = “M” N Y gender = “F” Meet marital N Y Not on marital Or gender Meet gender All done End
<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 write Pseudocode) 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.