Jump to content

divinedesigns1
 Share

Recommended Posts

hey guys can someone give me a simple but good ideal to create a program that uses if/else and while/do while? any simple program will do

Link to comment
Share on other sites

Hmmm... Yeah, tutorials are a good idea. But here are some examples any way: If, else:

yourName=prompt("Please enter your full name:","John Johnson");if (yourName=="John Johnson") {	alert("You used the standard name!");}else {	if (yourName.length<=5) alert("Your name is a little short...");	else if (yourName.length>5 && yourName.length<=25) alert("I like your name...");	else {		alert("Your name is too long.");	}}

Or this:

yourName=prompt("Please enter your full name:","John Johnson");if (yourName=="John Johnson") {	alert("You used the standard name!");}else if (yourName.length<=5) alert("Your name is a little short...");else if (yourName.length>5 && yourName.length<=25) alert("I like your name...");else {	alert("Your name is too long.");}

While/ Do-while:

name=prompt("Enter a name (maximum 30 characters):");if (name) {	while (name.length>30) {		name=prompt("Enter a name (maximum 30 characters).",name);	}}

Or this:

do {	name=prompt("Enter a name (maximum 30 characters):");} while(name && name.length>30);

Edited by ReGA
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...