none
If, Then statement not working RRS feed

  • Question

  • Here is the code:

     

    TextWindow.Write("Did you finish your homework? ")

    ans = TextWindow.Read()

    If (ans = TextWindow.Read(yes)) Then

      TextWindow.WriteLine(ans + "Congratulations " + fsn + "!")

    EndIf

    If (ans = TextWindow.Read(no)) Then

      TextWindow.WriteLine(ans + "Well, get started " + fsn + "!")

    EndIf

     

    I just started learning today so I'm sorry if this is such an easy question xD

     

    The error box below the code says:

    "The variable 'yes' is used, but its value is not assigned. Are you sure you have spelled it correctly?"

    "The variable 'no' is used, but its value is not assigned. Are you sure you have spelled it correctly?"

     

    Thing is, I don't know how to assign it. I thought I already did o.O

    Thanks in advance :D

     

    Sunday, November 6, 2011 3:36 AM

Answers

  • You are getting the error message because you are trying to compare a variable to a string, but you need to enclose "yes" and "no" inside of quotes. But TextWindow.Read() does not need any parameters!

    Also, you don't really need

    if (ans = TextWindow.Read()) then

    Anyway because you are asking for input twice.

    Try this:

    If (ans="Yes") Then

    But if you want to have it case insensitive, you will need to use the Text object to convert the variable "ans" to lower case.


    ~~AirWaves!!~~
    Sunday, November 6, 2011 3:49 AM

All replies

  • You are getting the error message because you are trying to compare a variable to a string, but you need to enclose "yes" and "no" inside of quotes. But TextWindow.Read() does not need any parameters!

    Also, you don't really need

    if (ans = TextWindow.Read()) then

    Anyway because you are asking for input twice.

    Try this:

    If (ans="Yes") Then

    But if you want to have it case insensitive, you will need to use the Text object to convert the variable "ans" to lower case.


    ~~AirWaves!!~~
    Sunday, November 6, 2011 3:49 AM
  • You are getting the error message because you are trying to compare a variable to a string, but you need to enclose "yes" and "no" inside of quotes. But TextWindow.Read() does not need any parameters!

    Also, you don't really need

    if (ans = TextWindow.Read()) then

    Anyway because you are asking for input twice.

    Try this:

    If (ans="Yes") Then

    But if you want to have it case insensitive, you will need to use the Text object to convert the variable "ans" to lower case.


    ~~AirWaves!!~~

    Alright so here's the new one:

     

    TextWindow.Write("Did you finish your homework? ")

    ans = TextWindow.Read()

    If (ans = yes) Then

      TextWindow.WriteLine("Congratulations " + fsn + "!")

    EndIf

    If (ans = no) Then

      TextWindow.WriteLine("Well, get started  " + fsn + "!")

    EndIf

     

    I'm still getting the same error messages :\ 

    How do I assign the variable to my answer?


    Sunday, November 6, 2011 3:55 AM
  • You're still missing the quotes around yes and no.

     

    If (ans = "yes")...

    If (ans = "no")...

    Tuesday, November 8, 2011 1:50 AM