1 00:00:00,210 --> 00:00:03,810 Before we start, did you try solving the workbook yourself? 2 00:00:03,840 --> 00:00:09,600 If not, please click the link in the resources folder and follow the instructions for this workbook. 3 00:00:10,860 --> 00:00:12,690 Welcome to Workbook 5.8. 4 00:00:12,720 --> 00:00:16,050 Task one is the story Secret number between one and five. 5 00:00:16,050 --> 00:00:18,480 So we'll say end secret. 6 00:00:18,820 --> 00:00:20,100 Let's set it to four. 7 00:00:20,370 --> 00:00:25,710 And then task two is to set up a loop that keeps the user guessing until they get the number right. 8 00:00:25,920 --> 00:00:30,060 So we chose a number between one and five. 9 00:00:30,060 --> 00:00:33,810 Then we prompt the user to try and guess it. 10 00:00:33,810 --> 00:00:36,330 So we will start by picking up their first choice. 11 00:00:36,330 --> 00:00:42,180 We will say int guess is equal to skin dot next int. 12 00:00:43,380 --> 00:00:47,010 And then after the user guesses, their first number will say while. 13 00:00:47,790 --> 00:00:51,570 The guess is not equal to the secret. 14 00:00:53,860 --> 00:01:00,040 We want to keep this loop running so long as what they guess does not match the secret, then we need 15 00:01:00,040 --> 00:01:02,320 to prompt them to enter another guess. 16 00:01:02,320 --> 00:01:04,480 So here we'll say guess again. 17 00:01:04,690 --> 00:01:07,600 System dot dot, print, not print line. 18 00:01:07,600 --> 00:01:13,060 Because if you look at the output, they guess beside the sentence that we print. 19 00:01:13,630 --> 00:01:15,580 So we'll say, guess again. 20 00:01:18,400 --> 00:01:22,680 And then said guess is equal to skin dot next and. 21 00:01:23,880 --> 00:01:30,550 So this wide loop will only ever break if what they end up guessing equals our secret number. 22 00:01:30,570 --> 00:01:35,070 Let us just visualize the runtime and see if our code is good. 23 00:01:41,780 --> 00:01:44,090 All right, so the secret number is four. 24 00:01:44,120 --> 00:01:46,610 I'm going to guess the number three. 25 00:01:48,190 --> 00:01:51,780 The number that we guessed three does not equal the secret. 26 00:01:51,790 --> 00:01:57,070 This evaluates the true so the wild loop runs, prompting us to guess again. 27 00:01:59,340 --> 00:02:02,120 Next, it waits for me to enter another integer. 28 00:02:02,130 --> 00:02:03,870 I'm going to guess number two. 29 00:02:05,810 --> 00:02:10,580 A guess of two does not equal the secret number, so the while loop gets invoked again. 30 00:02:11,030 --> 00:02:12,020 Guess again. 31 00:02:12,020 --> 00:02:14,330 Next end prompts me to enter an integer. 32 00:02:14,330 --> 00:02:16,070 I will enter the number one. 33 00:02:20,720 --> 00:02:23,740 A guess of one does not equal the secret of four. 34 00:02:23,750 --> 00:02:25,440 So this evaluates the true. 35 00:02:25,460 --> 00:02:27,110 Running the while loop again. 36 00:02:27,850 --> 00:02:30,700 This time I will guess the number for. 37 00:02:33,290 --> 00:02:33,830 All right. 38 00:02:33,830 --> 00:02:37,640 Four does equal the secret number that we chose. 39 00:02:37,640 --> 00:02:43,040 This evaluates the false the while loop breaks because we guessed correctly.