Challenge: Building a house data UI
Learnwebdevelopment/Core/Scripting/DebuggingJavaScript
Learn_web_development/Core/Scripting/Debugging_JavaScript
In this challenge we are going to get you to write some JavaScript for a house search/filter page on a property website. This will include fetching JSON data, filtering that data based on the values entered in provided form controls, and rendering that data to the UI. Along the way, we'll also test your knowledge of conditionals, loops, arrays and array methods, and more besides.
Starting point
To begin, click the Play button in one of the code panels below to open the provided example in the MDN Playground. You'll then follow the instructions in the Project brief section to complete the JavaScript functionality.
```html live-sample___house-ui-start live-sample___house-ui-finish
House search
Search for houses for sale. You can filter your search by street, number of bedrooms, and number of bathrooms, or just submit the search with no filters to display all available properties.
Results returned: 0
```css hidden live-sample___house-ui-start live-sample___house-ui-finish
body {
font: 1.1em / 1.5 system-ui;
width: clamp(480px, 90%, 1200px);
margin: 0 auto;
}
h1 {
font-size: 1.5em;
}
h2 {
font-size: 1.3em;
}
form div {
display: flex;
width: 100%;
max-width: 500px;
align-items: center;
margin-bottom: 20px;
}
label[for],
select {
flex: 1;
}
#output {
display: flex;
flex-flow: row wrap;
justify-content: center;
gap: 50px;
}
#output article {
padding: 0 20px;
background-color: #efefef;
border: 2px solid #cccccc;
border-radius: 10px;
}
#output ul {
list-style-type: none;
padding-left: 0;
}
```js-nolint live-sample___house-ui-start const streetSelect = document.getElementById("choose-street"); const bedroomSelect = document.getElementById("choose-bedrooms"); const bathroomSelect = document.getElementById("choose-bathrooms"); const form = document.querySelector("form");
const resultCount = document.getElementById("result-count"); const output = document.getElementById("output");
let houses;
function initializeForm() {
}
function renderHouses(e) { // Stop the form submitting e.preventDefault();
// Add rest of code here }
// Add a submit listener to the