JSFiddle - React, Tailwind, and code Playground

by James Hooper

HTML

<div class="knowledge-check">
  <div class="question-wrap">
    <div class="question" >
      What Day of the week is it?
    </div>
        <div class="note-correct hide">
      Well Done!
    </div>
    <div class="note-incorrect hide">
      Sorry that was incorrect
    </div>
    <div class="answer" a="n">
      Monday
    </div>
    <div class="answer" a="y">
      Tuesday
    </div>
    <div class="answer" a="n">
      Wednesday
    </div>
    <div class="answer">
      Thursday
    </div>
  </div>
</div>

CSS

.hide {
  display: none;
}

.knowledge-check {

}

.question {
  padding:20px;
  width:75%;
  margin:auto;
  text-align:center;
}

.answer{
  width: 75%;
  padding: 10px;
  text-align: center;
  background: #077cc1;
  margin: 10px auto;
  color:white;
}

.note-incorrect, .note-correct {
  padding:30px 20px;
  background:grey;
  text-align:center;
  width:75%;
  margin: 0 auto;
}

JavaScript

$(".answer").click(function(){
    
    var ans = $(this).attr("a");
    
    if (ans == "y") {
    	$(".note-incorrect").addClass("hide");
    	$(".note-correct").removeClass("hide");
    }
    
    else {
    $(".note-correct").addClass("hide");
    $(".note-incorrect").removeClass("hide");
    }
    
})