I wrote this little code to put a few skills together to make sure I am understanding the logic correctly.
*Code runs a prompt asking for your name
*Take the name and runs a prompt to ask your age.
*I have loops set up to make sure the fields are filled out correctly, if not it re-runs the prompt.
*The prompt to ask the age, keeps looping, I have the parameters set correctly it looks like, but it won't accept any number to end the loop.

**I emboldened the few lines of code I am having an issue with.

Thanks,
Russell

Code:

var counter= 0
//declares vaule to variable
var yourName= prompt("What is your name?")
//variable created from prompt
while(counter= 1){
//loop to run to ensure prompt is filled out
if (yourName.length== 0) {
//condtion to check if variable has a value
var yourName= prompt("What is your name?")
counter =1}
//counter set to re-run the loop if variable is blank

else {
//run the new prompt once variable has a value
counter= 2
var age= prompt(yourName+ " how old are you?")}
}
//declares value to new variable

var counter2= 0
while(counter2 = 1) {
//loop to verify content of prompt is correctly filled out
if (age <0 || age >99) {
//conditional to set parameters for the loop
var age= prompt(yourName+ " how old are you?")
counter =1}
//sets variable counter to 1 to re-run loop
else {
//sets counter to 2 to end loop and print a string
counter= 2
document.write("Hello "+ yourName+ " I see you are"+ age+ " years old.")
}

I did some more tinkering around with it, and I found the bug is in a different area of the code (new emboldened lines)

Code:

var counter= 0;
//declares value to variable
var yourName= prompt("What is your name?")
//variable created from prompt
while(counter= 1){
//loop to run to ensure prompt is filled out
if (yourName.length== 0) {
//condition to check if variable has a value
var yourName= prompt("What is your name?")
counter= 1}
//counter set to re-run the loop if variable is blank

else {
//run the new prompt once variable has a value
counter= 2
var age= prompt(yourName+ " how old are you?")}
}
//declares value to new variable

Of course none of those approaches will prevent a visitor using any browser except Internet Explorer from simply checking the checkbox at the bottom of the prompt either on its first appearance in Opera - where it turns off JavaScript - or on its second appearance in other browsers - where it turns off all further prompts, confirms and alerts.

02-10-2013, 09:35 PM

wise4aa

it runs

Thanks for the feedback yall, using values of true/false/null helped it run along with my mistakes of = instead of ==.