## Convert A String Into A Numeric Value

Hello Everyone,

I'm writing a script that will allow JD to give a short & simple math quiz to 6th grade special education students (my wife is a special ed teacher).

A challenge I have run into, is with converting the spoken text into a numeric value. For example:

``````
\$response = WaitForSpeech(30, &quot;4&quot;, &quot;3&quot;)

``````

Is not detecting when 4 or 3 is spoken, however when I use:

``````
\$response = WaitForSpeech(30, &quot;Four&quot;, &quot;Three&quot;)

``````

The response is detected and the value is stored as a string, but I can't do any math with it. I would like to actually perform calculations based on numbers provided by the student.

``````

``````

Any thoughts on how I can approach this differently?

Stay at the forefront of robot programming innovation with ARC Pro, ensuring your robot is always equipped with the latest advancements.

#1

You can do something like this

``````
if(\$response=&quot;one&quot;)
elseif(\$response=&quot;two&quot;)
elseif(\$response=&quot;three&quot;)
elseif(\$response=&quot;four&quot;)
#etc....
endif

``````
#2

LOL - Obviously. One of thoes Hommer Simpson moments :-) . Thanks @Richard

#3

Though, I like where you were taking this. It would be nice if your setup would work.

#4

@Technopro Thanks, I have a few goals for this 1st classroom appearance.

Dance to a song: Provide a mobile button + voice command that will trigger a sequence of frames and audio file.

Play peek-a-boo: Use the facial recognition to detect a student face, the game will consist of the student hiding his/her face then JD will say where did you go. When the student face appears, JD will say hey there you are.

Give a math quiz: I am coding in math problems that JD can give to students. JD will

1. begin by saying the problem what is the sum of 4 and 4,
2. begin listening for the answer spoken by the student.
3. evaluate the answer provided by the student and compare against the stored answer
4. Reply to student: Correct answer = flash LEDs and cheer Incorrect answer = flash LEDs and buzz incorrectly

Take a math quiz: I would like the students to give JD a math quiz, he will

1. begin listening for simple math question spoken by the student. (4+4)
2. detect the numbers and operation (only +, -, *, / options allowed)
3. evaluate
4. say the correct answer to the student

Basic Controls: Walk Forward Walk Backward Move head Vertical & Horizontal

I will post the video when completed.