The purpose of the code is to hide/show an element when the header element is clicked. Why code works and doesn't isn't clear.
Example 1
function showHideAnswers (id) {
var x = document.getElementById(id);
if (x.style.display === "") {
x.style.display = "block";
}
}
The above code works. Notice the display if comparision of "" rather than none.
Example 2
function showHideAnswers(id) {
var x = document.getElementById(id);
if (x.style.display === "none") {
x.style.display = 'block';
}
}
This code does not work. Notice display being compared to "none", which I think is the part that is causing it to fail; however, "none" works in example 3.
Example 3
function showHideAnswers(id) {
var x = document.getElementById(id);
if (x.style.display === "none") {
x.style.display = 'block';
} else {
x.style.display = 'none';
}
}
This code works, which causes me to be confused as to why example 2 doesn't work.