# Student created Webpage help!

**URL:** <https://forum.code.org/t/student-created-webpage-help/34211>\
**Category:** CS Principles\
**Tags:** csd-unit-2\
**Created:** [February 10, 2021, 12:58pm UTC](https://forum.code.org/t/student-created-webpage-help/34211 "2021-02-10T12:58:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rona\_williams](https://avatars.discourse-cdn.com/v4/letter/r/c6cbf5/32.png) [@rona\_williams](https://forum.code.org/u/rona_williams)\
**Post date:** [February 10, 2021, 12:58pm UTC](https://forum.code.org/t/student-created-webpage-help/34211/1 "2021-02-10T12:58:08Z")

</div>

Hello! I need help fixing a student’s issue…see below…

The purpose of this app is to help the user choose what type of dog they should adopt based on size and breed group. After the user chooses the size and breed group and clicks enter, the app will display a random name and random picture that match the size and breed group they have chosen in the previous screen. But sometimes the result is “undefined”. Like if you choose “Small” and “Toy”, the result will be undefined since there isn’t a dog breed from the table that matches both of the requirements.

So what I’m trying to do is make the screen display “Sorry. Please choose again” whenever the result is undefined. This is the code the student wrote, but it does not work:

var output = getText(“dogOutput”);  
if(output != filteredNames[randomIndex]){  
setText(“dogOutput”, “Sorry. Please try again.”);  
}

Here is a link to the student’s app:

> **[Check out what I made](https://studio.code.org/projects/applab/n4mb4ZR4_VrDyAPTkX3qvFm4d57NMSBmXqI36bcK2gw)**
>
> I wrote the code myself with Code.org

---

<div class="post-metadata">

**Author:** ![jdonwells](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/jdonwells/32/7900_2.png) [@jdonwells](https://forum.code.org/u/jdonwells)\
**Post date:** [February 10, 2021, 3:04pm UTC](https://forum.code.org/t/student-created-webpage-help/34211/2 "2021-02-10T15:04:45Z")

</div>

First, look at line 82 what should be added to `filteredImages`?

Lines 57 and 58. What is displayed in `"dogOutput"` if you set it then set it a second time?

Line 61. You are looking at the output of the code you just ran. What if you knew what the code would produce before you run it? How could you know that there are no suitable dogs in the filtered list? Could you use `filteredNames.length` somehow to know when there are no choices?

Big over all question here: Did you mean to always select a dog by Breed Group and ignore size or did you want to apply both size and breed together? Because right now you only choose from the breed group.

Sorry about all the questions. I have been hanging out with this guy Socrates too much I think.

---

<div class="post-metadata">

**Author:** ![rona\_williams](https://avatars.discourse-cdn.com/v4/letter/r/c6cbf5/32.png) [@rona\_williams](https://forum.code.org/u/rona_williams)\
**Post date:** [February 10, 2021, 3:42pm UTC](https://forum.code.org/t/student-created-webpage-help/34211/3 "2021-02-10T15:42:39Z")

</div>

The student meant to apply both the size and breed together.  
Updated version:

> **[Check out what I made](https://studio.code.org/projects/applab/n4mb4ZR4_VrDyAPTkX3qvFm4d57NMSBmXqI36bcK2gw)**
>
> I wrote the code myself with Code.org

They made it so that it will display two results. Is there a way to apply both size and breed group and still have only one result?

---

<div class="post-metadata">

**Author:** ![jdonwells](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/jdonwells/32/7900_2.png) [@jdonwells](https://forum.code.org/u/jdonwells)\
**Post date:** [February 10, 2021, 4:52pm UTC](https://forum.code.org/t/student-created-webpage-help/34211/4 "2021-02-10T16:52:57Z")

</div>

There are two ways to do that.

One way is to combine both the size and breed into the conditions in the `filter` function using `&&`.

Another way is to take the resulting arrays used in `filter` as input to `breedFilter`. So, filter for size then take the size filtered list of dogs and then filter for the breed. That yields a single list of dogs that meet both criteria. Right now you start both filters from the full list and end up with two different lists.

In either case the doublely filtered list can be empty.

---

<div class="post-metadata">

**Author:** ![rona\_williams](https://avatars.discourse-cdn.com/v4/letter/r/c6cbf5/32.png) [@rona\_williams](https://forum.code.org/u/rona_williams)\
**Post date:** [February 10, 2021, 6:48pm UTC](https://forum.code.org/t/student-created-webpage-help/34211/5 "2021-02-10T18:48:11Z")

</div>

Thank you for the help!!
