This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-11-03 16:01:55

cm744
New Scratcher
Registered: 2012-10-18
Posts: 2

Math Quiz Project

I'm trying to create this Math Quiz project where I construct a sprite to move around randomly ten times.  In order to win, I want the users to have to touch the sprite at least 3 times while it moves randomly and answer three simple math questions and give the sum total at the end.  Whenever the mouse pointer touches the sprite, I want the sprite to say one of three things: 1) Add (any random number ranging from -10 to 10), 2) subtract (any random number ranging from -10 to 10) or 3) multiply (any random number ranging from -5 to 5).

I want the Sprite to be able calculate the total  after being touched by the mouse pointer and randomly assigning 3 random operations (add, subtract, or multiply a random number).  When the user puts in the correct answer, I want the sprite to be able to tell the user if his/her answer is right or wrong.  If right, I want the sprite to say, "Correct!"  and ask the user to advance to the next level (I'd use broadcasting here I suppose?).  If the user's answer is wrong, I want the sprite to say "Wrong!  Try again!"  and start all over again.

I'm having a lot of difficulty creating the correct variables for this and getting the sprite to follow these commands.  If someone could give me the step-by-step commands for this, I would greatly appreciate it!

Offline

 

#2 2012-11-03 17:04:52

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Math Quiz Project

For the math problems, you could use something like this:

set [level v] to (1)
repeat until <(level) = (4)>
 if <(level) < (3)>//Picks the numbers for the problems.
  set [number v] to (pick random (-10) to (10))
  set [number2 v] to (pick random (-10) to (10))
 else
  set [number v] to (pick random (-5) to (5))
  set [number2 v] to (pick random (-5) to (5))
 end
 if <(level) = (1)>
  ask (join(join(join [What is ] (number)) [ + ]) (join (number2) [?])) and wait
  if <<(number) + (number2)> = (answer)>//Checks the answer.
    ask [Correct! Do you want to move on? (Y/N)] and wait
    if <(answer) = [Y]>
     change [level v] by (1)
    end
  else
   say [Wrong. Try again.]
  end
 else
  if <(level) = (2)>
   ask (join(join(join [What is ] (number)) [ - ]) (join (number2) [?])) and wait
   if <<(number) - (number2)> = (answer)>//Checks the answer.
    ask [Correct! Do you want to move on? (Y/N)] and wait
    if <(answer) = [Y]>
     change [level v] by (1)
    end
   else
    say [Wrong. Try again.]
   end
  else
   ask (join(join(join [What is ] (number)) [ x ]) (join (number2) [?])) and wait
   if <<(number) * (number2)> = (answer)>//Checks the answer.
    ask [Correct! Do you want to move on? (Y/N)] and wait
    if <(answer) = [Y]>
     change [level v] by (1)
    end
   else
    say [Wrong. Try again.]
   end
  end
 end
end
Sorry about only giving the script. If there's any part of it that you don't understand, just ask and I'll explain it.

Anyway, I hope that this helps!


http://i46.tinypic.com/35ismmc.png

Offline

 

#3 2012-11-03 17:44:14

cm744
New Scratcher
Registered: 2012-10-18
Posts: 2

Re: Math Quiz Project

Wow, this is very helpful, thank  you SO much!  I have one question, though. How do I get my sprite to ask these random math questions only when it is touched by the mouse pointer?  Thank you!

Offline

 

#4 2012-11-04 09:16:49

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Math Quiz Project

This would require several changes, so again, sorry about only giving the script:

when gf clicked
set [level v] to (1)
if (touching [mouse pointer v]?)
set [number v] to (pick random (-10) to (10))//This is here to make the script work.
repeat until <(number) = [P]>
 if <(level) < (3)>//Picks the numbers for the problems.
  set [number v] to (pick random (-10) to (10))
  set [number2 v] to (pick random (-10) to (10))
 else
  set [number v] to (pick random (-5) to (5))
  set [number2 v] to (pick random (-5) to (5))
 end
 if <(level) = (1)>
  ask (join(join(join [What is ] (number)) [ + ]) (join (number2) [?])) and wait
  if <<(number) + (number2)> = (answer)>//Checks the answer.
    ask [Correct! Do you want to move on? (Y/N)] and wait
    if <(answer) = [Y]>
     change [level v] by (1)
     set [number v] to [P]
    end
  else
   say [Wrong. Try again.]
  end
 else
  if <(level) = (2)>
   ask (join(join(join [What is ] (number)) [ - ]) (join (number2) [?])) and wait
   if <<(number) - (number2)> = (answer)>//Checks the answer.
    ask [Correct! Do you want to move on? (Y/N)] and wait
    if <(answer) = [Y]>
     change [level v] by (1)
     set [number v] to [P]
    end
   else
    say [Wrong. Try again.]
   end
  else
   ask (join(join(join [What is ] (number)) [ x ]) (join (number2) [?])) and wait
   if <<(number) * (number2)> = (answer)>//Checks the answer.
    ask [Correct! Do you want to move on? (Y/N)] and wait
    if <(answer) = [Y]>
     change [level v] by (1)
     set [number v] to [P]
    end
   else
    say [Wrong. Try again.]
   end
  end
 end
end
end
I hope that this helps!

Last edited by ErnieParke (2012-11-04 09:17:54)


http://i46.tinypic.com/35ismmc.png

Offline

 

#5 2012-11-04 09:24:51

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: Math Quiz Project

ErnieParke wrote:

This would require several changes, so again, sorry about only giving the script:

when gf clicked
set [level v] to (1)
forever
if (touching [mouse pointer v]?)
set [number v] to (pick random (-10) to (10))//This is here to make the script work.
repeat until <(number) = [P]>
 if <(level) < (3)>//Picks the numbers for the problems.
  set [number v] to (pick random (-10) to (10))
  set [number2 v] to (pick random (-10) to (10))
 else
  set [number v] to (pick random (-5) to (5))
  set [number2 v] to (pick random (-5) to (5))
 end
 if <(level) = (1)>
  ask (join(join(join [What is ] (number)) [ + ]) (join (number2) [?])) and wait
  if <<(number) + (number2)> = (answer)>//Checks the answer.
    ask [Correct! Do you want to move on? (Y/N)] and wait
    if <(answer) = [Y]>
     change [level v] by (1)
     set [number v] to [P]
    end
  else
   say [Wrong. Try again.]
  end
 else
  if <(level) = (2)>
   ask (join(join(join [What is ] (number)) [ - ]) (join (number2) [?])) and wait
   if <<(number) - (number2)> = (answer)>//Checks the answer.
    ask [Correct! Do you want to move on? (Y/N)] and wait
    if <(answer) = [Y]>
     change [level v] by (1)
     set [number v] to [P]
    end
   else
    say [Wrong. Try again.]
   end
  else
   ask (join(join(join [What is ] (number)) [ x ]) (join (number2) [?])) and wait
   if <<(number) * (number2)> = (answer)>//Checks the answer.
    ask [Correct! Do you want to move on? (Y/N)] and wait
    if <(answer) = [Y]>
     change [level v] by (1)
     set [number v] to [P]
    end
   else
    say [Wrong. Try again.]
   end
  end
 end
end
end
I hope that this helps!

Need that forever.


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

Board footer