Refactoring if's, what's the mistake?
-
How to put type = "radio" state in if as checked?
Previously, it worked like this for me:
if (document.getElementById('radiobutton').checked) { user_choice = "EAGLE"; console.log(user_choice); return; } if (document.getElementById('radiobutton2').checked) { user_choice = "TAILS"; console.log(user_choice); return; } else { user_choice = null;
Now I want to fix it with a construction of the form
const user_choice = document.getElementById('radiobutton').checked=true ? user_choice = "EAGLE" : user_choice = "TAILS";
JavaScript Anonymous, Mar 10, 2020 -
const user_choice = document.getElementById('radiobutton').checked ? "EAGLE" : "TAILS";
Anonymous
1 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!