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

I once had a whim and I had to obey it to buy a french horn from a second hand shop, I polished it up and I started to play it in spite of the neighbours who begged me to stop. To sound my horn, I had to develop my embouchure, I found my horn, was a bit of a devil to play. So artfully wound, to give you a sound, a beautiful sound, so rich and round. Oh, the hours I ha-ad to spend before I mastered it in the end! But that was yesterday, and just today I looked in the usual place. There was the case, but the horn itself was missing! Who? Swiped? That? Horn? I'll bet you a quid, somebody did! Knowing I found a concerto and wanted to play it afraid of my talent at playing the horn, for early today to my utter dismay it had vanished away like the dew in the morn. Tutti. I've lost that horn, I know I was using it yesterday, I've lost that horn, lost that horn, found that horn gorn! There's not much hope of getting it back though I'd willingly pay a reward. I know some hearty folk whose party joke's pretending to hunt with the Quorn. Gone away! Gone away! Was it one of them took it away? I shall tell the police! I! Want! That! French! Horn! Baaaaaack… I miss its music more and more and more, without that horn, I'm feeling sad and so forlo-orn… (oooooooh) I found a concerto and wanted to play it displaying my talent at playing the horn, but early today to my utter dismay it had totally vanished away! I practised the horn and I wanted to play it but somebody took it away, I practised the horn and was longing to play it but somebody took it away! My neighbour's asleep in his bed. I'll soon make him wish he were dead. I'll take up the tuba instead - wah wah!
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).

I once had a whim and I had to obey it to buy a french horn from a second hand shop, I polished it up and I started to play it in spite of the neighbours who begged me to stop. To sound my horn, I had to develop my embouchure, I found my horn, was a bit of a devil to play. So artfully wound, to give you a sound, a beautiful sound, so rich and round. Oh, the hours I ha-ad to spend before I mastered it in the end! But that was yesterday, and just today I looked in the usual place. There was the case, but the horn itself was missing! Who? Swiped? That? Horn? I'll bet you a quid, somebody did! Knowing I found a concerto and wanted to play it afraid of my talent at playing the horn, for early today to my utter dismay it had vanished away like the dew in the morn. Tutti. I've lost that horn, I know I was using it yesterday, I've lost that horn, lost that horn, found that horn gorn! There's not much hope of getting it back though I'd willingly pay a reward. I know some hearty folk whose party joke's pretending to hunt with the Quorn. Gone away! Gone away! Was it one of them took it away? I shall tell the police! I! Want! That! French! Horn! Baaaaaack… I miss its music more and more and more, without that horn, I'm feeling sad and so forlo-orn… (oooooooh) I found a concerto and wanted to play it displaying my talent at playing the horn, but early today to my utter dismay it had totally vanished away! I practised the horn and I wanted to play it but somebody took it away, I practised the horn and was longing to play it but somebody took it away! My neighbour's asleep in his bed. I'll soon make him wish he were dead. I'll take up the tuba instead - wah wah!
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