Working with dropdown list items in JavaScript

Let us have a reference to the option tag in a variable. For example, obtained as follows:

let option = document.querySelector('#option'); let option = select[0];

In this case, the text property will store the text of the option, the value property will store the value of the attribute of the same name, and the selected property will store the value of true or false depending on whether the list item is selected or not:

console.log(option.text); console.log(option.value); console.log(option.selected);

Go through the list items in a loop and add an exclamation mark to the end of the text for the selected item, and a question mark for unselected items.