Unit 2 Webpage help

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:

Hi @rona_williams,

Are you perhaps looking for the CS Principles forum for the high school class, https://forum.code.org/c/csp? This one is for CS Discoveries and we don’t get that in depth with traversals or arrays in this curriculum.

I hope they’re able to assist you!

–Michael K.

Ok, yes!! Sorry!! And thank you!

1 Like