Почему этот код не скрывает сообщение "Поздравления" в div, когда функция вызывается с аргументом (false)?
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div id="winner">Congratulations!</div>
<script>
var winner = function winOrNot(winner) {
//if the variable winner has the value of true, show the div with id "winner"
if(winner) {
document.getElementById('winner');
}
//otherwise, hide the div if the value of winner is false
else {
document.getElementById('winner').style.display = 'none';
}
winOrNot(false);
}
</script>
</body>
</html>
ОБНОВЛЕНИЕ: Спасибо за ваши предложения. Я обновил мой код с вашими идеями, но я все равно получаю тот же результат после сохранения изменений и запуска кода. Вот ревизия:
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
#winner {
display:block;
}
</style>
</head>
<body>
<div id="winner">Congratulations!</div>
<script>
var winner = function winner(winner) {
//if the variable winner has the value of true, show the div with id "winner"
if(winner) {
document.getElementById('winner');
}
//otherwise, hide the div if the value of winner is false
if(winner===false) {
document.getElementById('winner').style.display = 'none';
}
}
winner(false);
</script>
</body>
</html>