Skip to content

Instantly share code, notes, and snippets.

@toomasv
Created September 21, 2020 15:16
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save toomasv/c64c3d3380e4b6dc726fdda12b449b7b to your computer and use it in GitHub Desktop.
Quiz about capitals
Red []
page: read-thru/binary https://geographyfieldwork.com/WorldCapitalCities.htm
quiz: does [
capitals: clear []
loop 5 [
list: head page
loop (random 200) - 1 [
l: find list <td height="17"> list: find l </tr>
]
parse to-string copy/part l: find list <td height="17"> list: find l </tr> [
collect into capitals 2 [thru {"17">} keep to #"<"]
]
]
forall capitals [if crap: find capitals/1 " (" [clear crap]]
countries: reverse copy capitals
questions: copy capitals
forall questions [
poke questions 1 + make integer! random true '?
questions: next questions
]
foreach [country capital] questions [
case [
country = '? [
correct: no
answer: ask rejoin ["^/Which country has " capital " for its capital? "]
unless correct: answer = select countries capital [
loop 2 [
answer: ask random/only ["Nope! " "Naagh! " "Try again: "]
if correct: answer = select countries capital [break]
]
]
print pick [
["Yes," capital "is capital of" answer]
["Correct answer is:" select countries capital]
] correct
]
capital = '? [
correct: no
answer: ask rejoin ["^/What is the capital of " country "? "]
unless correct: answer = select capitals country [
loop 2 [
answer: ask random/only ["Nope! " "Nooo! " "Try more: "]
if correct: answer = select capitals country [break]
]
]
print pick [
["Yep, the capital of" country "is" answer]
["Correct answer is:" select capitals country]
] correct
]
]
]
]
quiz
@Rebol2Red
Copy link

Hi Toomas,

If i run your program it quits immediately so does nothing except when i insert print [] just after quiz: does [ print [] ...
I can't find out why. Maybe you have a clue?
Red 0.6.4 for Windows built 24-Nov-2020/11:59:06+01:00 commit #03a5dd6

@toomasv
Copy link
Author

toomasv commented Nov 25, 2020

Hmm, it works OK here.

Try

https://gist.githubusercontent.com/toomasv/c64c3d3380e4b6dc726fdda12b449b7b/raw/d4686a7434f1e93c4fbe04f2e8ebd06708b20c0a/quiz.red

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment