Discuss Scratch

polargiant3
New to Scratch
2 posts

Coding Word Problem in Script

I'm working on a lesson plan called “Interactive Word Problem Posters” from Makey Makey. The coding is partially done in the script but how do I know if the answer is right or wrong? Please see the link to my script below.

https://scratch.mit.edu/projects/199305873/#editor

Thank you!
Michelle Thomas
DaEpikDude
Scratcher
1000+ posts

Coding Word Problem in Script

Well, there are a few problems with your script that you can change:
1: To divide something by something, you can't just type “12/4” in the box.
<[12/4] =[3]>
would check if “12/4” is the same as “3”, which it isn't. You need to use the divided by block, i.e.
<((12) / (4)) = [3]>
Also, that would just check if 12 / 4 = 3 which would always return true. To use the ask block, you also use the block “answer” which is right next to the ask block.
So your code would look like:
if <(answer) = [3]> then
...
end
I also noticed that you can optimise your code: since it checks if the answer is correct, then constantly repeats if it's not, you can do this instead:
ask [question so and so] and wait
repeat until <(answer) = [the answer]> // if it's right in the first place this will never happen
ask [That's not right, try again] and wait
end
say [you did it yay congrendulates]

Also, for future reference, when you have a problem with code you might want to put your topic in the Help with Scripts forum. I'll report this thread to be moved for you

Come join the Memes and Trends studio!
In a few months this one studio along with the related topics has had just about the wildest history of anything on the website. It's beautiful.
Just expect to get S P I C E D H A M
polargiant3
New to Scratch
2 posts

Coding Word Problem in Script

Hello,
How do you make the program repeat until the student gets the problem right?
https://scratch.mit.edu/projects/199305873/#editor
Thank You!
Michelle Thomas
DaEpikDude
Scratcher
1000+ posts

Coding Word Problem in Script

Right now your program isn't actually using the student's answer, it's just checking if 12 / 4 is 3, which of course it is.
To fix this just replace the “12 / 4” block with the answer block (which is right next to ask and wait).

Come join the Memes and Trends studio!
In a few months this one studio along with the related topics has had just about the wildest history of anything on the website. It's beautiful.
Just expect to get S P I C E D H A M
omega_red
Scratcher
6 posts

Coding Word Problem in Script

Saying ‘repeat until 12/4=3’ is the same as saying ‘repeat until 1=1’, which will always be true, no matter what the answer. maybe try this :
repeat until <(answer) = [3]>
ask [whats 12/3?] and wait

end

Last edited by omega_red (Feb. 9, 2018 08:51:24)

asivi
Scratcher
1000+ posts

Coding Word Problem in Script

omega_red wrote:

Saying ‘repeat until 12/4=3’ is the same as saying ‘repeat until 1=1’, which will always be true, no matter what the answer. maybe try this :
repeat until <(answer) = [3]>
ask [whats 12/3?] and wait

end

4?


Powered by DjangoBB

Standard | Mobile