Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

If conditions


Published on

if conditions in javascript

Published in: Data & Analytics
  • Be the first to comment

  • Be the first to like this

If conditions

  1. 1. The if condition While writing a program, there may be a situation when you need to adopt one path out of the given two paths. So you need to make use of conditional statements that allow your program to make correct decisions and perform right actions. JavaScript supports conditional statements which are used to perform different actions based on different conditions. JavaScript supports following forms of if..else statement:  if statement  if...else statement  if...else if... statement.
  2. 2. Copy the following program into dreamweaver and test it. <html> <body> <script type = "text/javascript"> var age = prompt ("what is your age?",""); age = parseInt(age); if (age >65) { document.write ("you are a senior citizen"); } </script> </body> </html>
  3. 3. Add this piece of code into the program. else (age <65) { document.write ("you are not a senior citizen"); }
  4. 4. Make your own quiz by changing the following code into your own question and answers <script type = “text/javascript”> var answer1=prompt('How many moons does Earth have?',''); if (answer1 == 1 ) { alert('Correct!'); } else { alert('Sorry. The correct answer is 1'); } var answer2=prompt('How many moons does Saturn have?',''); if (answer2 == 31) { alert('Correct!'); } else { alert('Sorry. The correct answer is 31'); } </script>