WEBVTT

0
00:00.390 --> 00:01.380
In the last lesson,

1
00:01.410 --> 00:06.330
we got our quiz app to start displaying the questions that we were getting from

2
00:06.360 --> 00:10.560
our API. This question I landed on is pretty interesting.

3
00:10.650 --> 00:13.200
Nintendo started out as a playing card manufacturer?

4
00:13.560 --> 00:16.500
And I would love to know if that's actually true or false.

5
00:17.070 --> 00:20.310
So I'd really like these buttons to work basically.

6
00:20.700 --> 00:22.560
If I click on one of these buttons,

7
00:22.620 --> 00:27.090
I want to be able to check my answer against the real answer that we got back

8
00:27.090 --> 00:31.230
from our API. So in this lesson, that's what we're going to get to work.

9
00:32.070 --> 00:34.020
So I want this to be a bit of a challenge for you.

10
00:34.560 --> 00:39.560
We know that we can add a command argument to our buttons so that it calls a

11
00:41.490 --> 00:46.170
particular method when it gets pressed. Now, when that method gets pressed,

12
00:46.620 --> 00:51.620
we want to go into our quiz brain and call this check answer.

13
00:52.530 --> 00:57.480
Now this check answer method expects a answer to check against.

14
00:57.840 --> 01:02.700
Have a think about how you might solve this and get this to work so that we can

15
01:02.700 --> 01:07.290
start printing out whether if we got the question right or the question

16
01:07.290 --> 01:10.860
wrong. Pause the video now, and try to complete this challenge.

17
01:10.910 --> 01:11.743
<v 1>Go. </v>

18
01:15.950 --> 01:17.360
<v 0>Okay. Here's the solution.</v>

19
01:18.080 --> 01:23.080
The first thing I'm going to do is create a new method called true_pressed

20
01:26.930 --> 01:30.050
and also a method called a false_pressed.

21
01:31.430 --> 01:36.430
This true_pressed is obviously going to be the one that will be the command for

22
01:37.100 --> 01:40.820
this true button and it's going to be self.

23
01:40.820 --> 01:44.900
true_pressed because we're inside a class and we have to make sure that there's

24
01:44.900 --> 01:49.280
no parentheses at the end of it because we only want to trigger this method

25
01:49.580 --> 01:54.530
when the button actually detects a click. In a similar way,

26
01:54.530 --> 01:58.250
we're going to add a command to the false button and it's going to be

27
01:58.250 --> 02:02.360
self.false_pressed. And again, deleting the parenthesis.

28
02:02.840 --> 02:05.210
And now we can figure out what to do in here.

29
02:05.930 --> 02:10.190
We already have access to our quiz brain object in here

30
02:10.520 --> 02:13.700
which is saved under self.quiz.

31
02:14.210 --> 02:16.280
When either of these gets pressed,

32
02:16.400 --> 02:21.400
then we can simply tap into self.quiz and we can call the check_

33
02:22.190 --> 02:24.770
answer method that exists over there.

34
02:25.310 --> 02:29.090
And we can pass over true when true_pressed is called,

35
02:29.480 --> 02:31.880
and then when false_pressed is called

36
02:31.880 --> 02:32.713
<v 1>...</v>

37
02:34.760 --> 02:38.870
<v 0>we'll pass in false. Now it's going to go into this check_answer,</v>

38
02:38.930 --> 02:43.040
pass that answer in and it's going to print out whether if you got it right

39
02:43.220 --> 02:45.950
or whether if you got it wrong. So let's test that out.

40
02:46.400 --> 02:51.400
Let's run the code again and make sure that we don't make any silly typos like

41
02:52.400 --> 02:53.300
comand.

42
02:53.630 --> 02:54.463
<v 1>Yeah.</v>

43
02:56.330 --> 03:00.490
<v 0>So let's run our app and see if can answer some questions.</v>

44
03:01.450 --> 03:04.570
Gumbo is a stew that originated in Louisiana.

45
03:05.260 --> 03:06.760
I think that might be true.

46
03:08.590 --> 03:10.540
And when I click on the button,

47
03:10.570 --> 03:14.230
you can see in the console it's printed whether

48
03:14.230 --> 03:16.720
if I got it right or wrong. Now,

49
03:16.720 --> 03:21.720
while our code works and we can see whether we got it right or wrong in the

50
03:22.060 --> 03:24.790
console, that's not something the user will see.

51
03:24.790 --> 03:28.120
This is only something that's available to us as developers.

52
03:28.630 --> 03:31.330
So how can we give the user some feedback?

53
03:31.900 --> 03:33.970
That's what we'll figure out in the next lesson.