0
const fruits = ['Apple', 'Banana', 'Orange']; console.log(fruits.length); // 3 const first = fruits[0]; console.log(first); // Apple const last = fruits[fruits.length - 1]; console.log(last); // Orange console.log(first[1]); // What is the output?
<form action="" method="post" id="my-form"> <label><input type="radio" name="colors" value="red" />Red</label> <label><input type="radio" name="colors" value="blue" />Blue</label> <label><input type="radio" name="colors" value="yellow" />Yellow</label> <label><input type="radio" name="colors" value="green" />Green</label> </form>
name
RadioNodeList
form.elements
const colors = document.getElementById("my-form").elements["colors"]; console.log(colors[0].checked); console.log(colors[0].value);
value
if
let userChoice; if (colors[0].checked) { userChoice = colors[0].value; } else if (colors[1].checked) { userChoice = colors[1].value; } else if (colors[2].checked) { userChoice = colors[2].value; } else { userChoice = colors[3].value; } console.log(userChoice);
for
for ([initialExpression]; [condition]; [incrementExpression]){ statement }
let userChoice; for (let i = 0; i < colors.length; i++) { if (colors[i].checked) { userChoice = colors[i].value; // break; // exit the loop } } console.log(userChoice);
ex18.html
textarea
select
option
sitemap.html