You shouldn’t set the value prop here, just the placeholder - that defeats the purpose of the placeholder.
<p class="alert__p">
- Instructions: <br>
1) Select a lenguage and voice. <br>
2) Write something in the field. <br>
3) Press the button. <br>
4) Listen to the voice.
</p>
This should be an ordered list.
Your switch statement should have a default. Why not have let voice be undefined when it is created and then your default could just be fore the UK Female. It would eliminate a little code. Actually I probably would have wrapped that switch logic in its own function so it could just return that value instead of setting a variable and breaking - but that’s more a stylistic choice than a criticism. Or actually, a dictionary would work well there too. But again, more stylistic.
... .addEventListener("click", e=>{
Why are you passing in e? I’d rather just have empty parentheses there, otherwise I assume that the function is doing something with that variable.
But all in all, it looks pretty good. I can’t find much to complain about.
I would suggest you check out the FormData interface. If you just change the option values to the voice values you need it would be a lot easier.
<form>
<select name="voice">
<option value="UK English Female">UK English Female</option>
<option value="UK English Male">UK English Male</option>
<option value="US English Female">US English Female</option>
<option value="Spanish Latin American Female">Spanish Latin American Female</option>
<option value="Spanish Female">Spanish Female</option>
</select>
</form>
const form = document.querySelector("form");
document.querySelector("button").addEventListener("click", () => {
const formData = new FormData(form);
const voice = formData.get("voice");
responsiveVoice.speak(document.querySelector("input").value, voice);
});
Thanks a lot for time your time and give me feedback! Your solution are definitely more elegant (personal opinion) and that’s what I was looking for!
Thanks again! I will be careful with the english words, using correct tags and finding ways to write less and cleaner code.
Your solution is amazing! I didn’t know this way to do it, is a lot better than my Switch/Case. I’m going to learn more about FormData interface. Thanks!