I am still a newbie at JavaScript and have not done any internships or formal work on web development.
The HTML have 3 radio buttons and the h4 tag is for displaying some text/result based on radio button selection.
HTML:
<p>The 3 sages of the apocalypse</p>
<input id="cat" type="radio" name="3sages">
<label >Luceila of the South</label><br>
<input id="fav" type="radio" name="3sages">
<label >Isley of the North</label><br>
<input id="split" type="radio" name="3sages">
<label >Riful of the west</label><br>
<h4 id="display"></h4>
The lab requirements is such that I must use promises and when the promise object is rejected a different function call must take place. Promise is hard to understand as I have googled for 2 hours last week and cannot understand. What purpose does .then serve? Is it using the promise object?
JavaScript (not working):
$('input[type=radio][name=3sages]').change(function()
{
function wrong()
{
const write = document.getElementById("display");
write.innerHTML = "Wrong";
}
function correct()
{
const write = document.getElementById("display");
write.innerHTML = "He is my favorite";
}
let guarantee = new Promise(function(resolve,reject) {
if ($('#fav').is(':checked'))
{
resolve(correct());
}
else
{
reject(wrong());
}
});
guarantee.then(
function()
{
correct();
},
function()
{
wrong();
}
);
});