I am trying to save the values of a are you bored API then call it in Final DATA After that i call it it gives me undefind for the first call , then I call it and it gives me undefined then it works fine, how can I fix it?
<section >
<form action="" class="form__wrapper">
<div class="participants__wrapper">
<label id="participants__label" for="participants">For how much people the activity:</label>
<input type="number" id="participants" name="participants">
</div>
<div>
<label for="price-range" id="price-range__label">Your price range:</label>
<input type="range" name="price-range" id="price-range" min="0" max="1" step="0.1">
</div>
<div>
<button type="submit" id="sumbuit__button">Submit</button>
</div>
</form>
const howMuchPll = document.querySelector(`#participants`);
const priceRange = document.querySelector(`#price-range`);
const btn = document.querySelector(`#sumbuit__button`);
const form = document.querySelector(`form`);
let valueForPpl = "";
let valueForPriceRange = "";
let FinalDate = [{}];
const boredApiHandler = async () => {
try {
const mainData = await fetch(
`http://www.boredapi.com/api/activity/?participants=${valueForPpl}&price=${valueForPriceRange}`
);
const parsedData = await mainData.json();
return (FinalDate = parsedData);
} catch {}
};
const howMuchPllHandler = (e) => {
let inputValue = e.target.value;
return (valueForPpl = inputValue);
};
const priceRangeHandler = (e) => {
let priceRangeValue = e.target.value;
return (valueForPriceRange = priceRangeValue);
};
howMuchPll.addEventListener(`change`, howMuchPllHandler);
priceRange.addEventListener(`change`, priceRangeHandler);
form.addEventListener(`submit`, (e) => {
e.preventDefault();
boredApiHandler();
console.log(FinalDate.activity);
});