Check out a free preview of the full JavaScript: From First Steps to Professional course:
The "Doggo Quiz while Review" Lesson is part of the full, JavaScript: From First Steps to Professional course featured in this preview video. Here's what you'd learn in this lesson:

Anjana inserts the correct function argument and demonstrates the resulting code from the doggo quiz while exercise.

Get Unlimited Access Now

Transcript from the "Doggo Quiz while Review" Lesson

[00:00:00]
>> We're getting there but we noticed something, can you say that again?
>> Push is pushing nothing.
>> Right now we're pushing nothing, so we have to push the actual thing we care about, so we just need to add.
>> Candidate.
>> Candidate, okay. So now what we've got hopefully, is a function, and I'm just gonna copy paste this so that we can try it out in our console.

[00:00:33] Let's try it out. We're gonna need getRandomElement and shuffleArray too, so let me grab those, and I will explain later why I'm not just reloading the page. Okay, so we've got our getRandomElement. We've got our shuffleArray. Those are the, we could say, dependencies of this function, or the things that this function depends on, that it needs to run.

[00:00:58] And then we're going to declare our, getMultipleChoices function. Probably the most complex function we've written so far. Okay, so now if I pass in, let's say, getMultipleChoices, and I want three choices. And let's say we're doing JavaScript types, and the correct answer is, I don't know, boolean, and I'm passing an array of some other JavaScript types.

[00:01:27] So boolean is one of them, what else we got? Help me out, types in JavaScript, string.
>> Primitive.
>> Yep, other primitive types, number, undefined, yeah, etc, object. Okay, so if we've done this right then hopefully we should get some choices that include boolean and two other things and in whatever, random order.

[00:01:56] Let's find out. All right, boolean, object, undefined. Try it again, string, boolean, number,. Let's try it again, object, boolean, number, cool. Now let's just double check our understanding and make sure that this actually is flexible. What happens if we make it two choices? All right, that's good. That feels good, we're getting two things out now.

[00:02:19] How about four choices? Okay, feeling confident? Now what if we change the correct answer? I mean, it's a little hard to tell cuz there's booleans and strings everywhere but, There we go, that one doesn't have boolean in it, so we know that it's using the string as the correct answer.

[00:02:42] And are we seeing any multiple elements? No, y'all, we have a super weird, but correctly functioning function here. We have a functioning function which is always a win. So right now what we just did, we just used a lot of stuff that we have just learned so far in the course.

[00:03:10] So we've got arrays, we've got mutating arrays, we've got while loops, we've got conditions. We've got operators, we've got the logical operator NOR, we have an if loop, we have randomness. We have built in methods like includes, we have a lot going on. Now we're starting to get a sense of really what it feels like to be working with JavaScript.

[00:03:36] You have so many tools in your toolbox, and it's our job as coders to decide which tools are appropriate for which jobs. So do we need a screwdriver right now or do we need a hammer? Do we need a chainsaw or do we need a paintbrush? So as we get more and more tools in our JavaScript toolbox, our work is gonna become less like going to MDN and figuring out the new tool.

[00:04:02] And more going to MDN and figuring out is this the tool that I really want for this job, and making choices and making decisions?