Skip to content

Instantly share code, notes, and snippets.

@Roner1k
Last active April 30, 2020 16:33
Show Gist options
  • Select an option

  • Save Roner1k/d578c43a4e61c31c81491ff5bb4169ea to your computer and use it in GitHub Desktop.

Select an option

Save Roner1k/d578c43a4e61c31c81491ff5bb4169ea to your computer and use it in GitHub Desktop.
add hidden radio buttons with Value=1 and default check in yours html
// 9
function Ninth() {
let question1Value = +document.querySelector('input[name="que1"]:checked').value,
question2Value = +document.querySelector('input[name="que2"]:checked').value,
question3Value = +document.querySelector('input[name="que3"]:checked').value,
result;
if (question1Value === 1 || question2Value === 1 || question3Value === 1) {
modalo();
document.getElementById('result-ninth').value = 'Сделайте выбор , пожалуйста!';
return 0;
} else {
result = question1Value + question2Value + question3Value;
switch (true) {
case (result === 6):
document.getElementById('result-ninth').value = 'Вы набрали ' + result + ' балов , Молодчинка!';
break;
case (result === 4):
document.getElementById('result-ninth').value = 'Вы набрали ' + result + ' балов , Можно и лучше!';
break;
case (result === 2):
document.getElementById('result-ninth').value = 'Вы набрали ' + result + ' балов , Мда...!';
break;
case (result === 0):
document.getElementById('result-ninth').value = 'Вы набрали ' + result + ' балов , Это печально...!';
break;
default:
document.getElementById('result-ninth').value = 'Что-то пошло не так...';
}
modalo();
}
function modalo() {
$('#open-door').click(function () {
$('.modal-wrap').fadeIn();
});
$('.close-me').click(function () {
$('.modal-wrap').fadeOut();
});
}
};
/* some HTML */
<div class="questions">
<h3> "2"+ 2 = ?</h3>
<div class="row">
<input type="radio" id="que3-s1" name="que3" value="0">
<label for="que3-s1">4</label>
</div>
<div class="row">
<input type="radio" id="que3-s2" name="que3" value="0">
<label for="que3-s2">"2"2</label>
</div>
<div class="row">
<input type="radio" id="que3-s3" name="que3" value="2">
<label for="que3-s3">22</label>
</div>
<label class="d-none"></label>
<input type="radio" class="d-none" name="que3" value="1" checked>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment