Привет, я новичок, поэтому, пожалуйста, извините за мой базовый код, я пытаюсь распечатать результат расчета жизненного пути, но он, похоже, не определяет результат, который я хочу получить.
Итак, я изменил свой код в соответствии с приведенным примером. Вот функция calculator (), в которой я получаю значение FinalLifeNumber и передаю его в switchVisible ().
document.getElementById("PathNumber").innerHTML = "Life Path Number: " + sumMonth + sumDays + FinalYear + " = " + FinalLifeNumber;
switchVisible(FinalLifeNumber);
}
пытаясь передать его следующей функции switchVisible (), которая должна выводить классы div, которым он равен.
function switchVisible(FinalLifeNumber) {
var cal = FinalLifeNumber;
document.getElementsByClassName('LP1')[0].style.display = "none";
document.getElementsByClassName('LP2')[0].style.display = "none";
document.getElementsByClassName('LP3')[0].style.display = "none";
document.getElementsByClassName('LP4')[0].style.display = "none";
document.getElementsByClassName('LP5')[0].style.display = "none";
document.getElementsByClassName('LP6')[0].style.display = "none";
document.getElementsByClassName('LP7')[0].style.display = "none";
document.getElementsByClassName('LP8')[0].style.display = "none";
document.getElementsByClassName('LP9')[0].style.display = "none";
switch (cal) {
case 1: document.getElementsByClassName('LP1')[0].style.display = "block"; break;
case 2: document.getElementsByClassName('LP2')[0].style.display = "block"; break;
case 3: document.getElementsByClassName('LP3')[0].style.display = "block"; break;
case 4: document.getElementsByClassName('LP4')[0].style.display = "block"; break;
case 5: document.getElementsByClassName('LP5')[0].style.display = "block"; break;
case 6: document.getElementsByClassName('LP6')[0].style.display = "block"; break;
case 7: document.getElementsByClassName('LP7')[0].style.display = "block"; break;
case 8: document.getElementsByClassName('LP8')[0].style.display = "block"; break;
case 9: document.getElementsByClassName('LP9')[0].style.display = "block"; break;
}
}
Это примерный класс div.
<div class="LP1">
<p id="LifePlan1">
<h1 style="background-color:brown;"><b> The Natural Born Leader </b></h1>
The Life Path 1 is one of leadership and trailblazing. With a strong sense of independence, you do not like relying on other people, especially if you feel they are holding you back. Often, you may feel like it is better to go it alone.
<br />
You would do well as an entrepreneur because you aren't afraid to take risks! You march to the beat of your own tune and the people around you generally don't hear until the tune is completed and on the top 100 charts. You tend to do things your own way and create innovation by stirring up the pot. People such as Henry Ford, Charlie Chaplin, Ozzy Osbourne, Tom Cruise, all stayed true to their Life Path 1, you should too.
<br />
As a Life Path 1, be careful and don't try to control everything and everyone around you as you plow headlong towards your goals. In life it is still beneficial to maintain a balance.
<br />
Confidence, creativity, and originality are very popular characteristics of a Life Path 1.
</p>
</div>
И этокнопка, чтобы показать это.
<input type="submit" value="calculate" onclick="calculator(); switchVisible(FinalLifeNumber);" style="background-color:cornflowerblue; object-position:100px;"/>
Это то, что я вижу только потом.
![enter image description here](https://i.stack.imgur.com/AA2JS.png)