五行姓名打分测试

anleey1880

五行姓名打分测试

姓名对一个人一生的运势有着重要的影响。五行姓名打分测试可以帮助你了解你的姓名五行属性,并对你的运势进行评估。

javascript const form = document.querySelector('form');form.addEventListener('submit', (event) => {event.preventDefault();const name = document.querySelector('name').value;const result = calculateScore(name);document.querySelector('result').innerHTML = `你的姓名五行属性为${result.五行属性},五行得分${result.五行得分}分。`; });function calculateScore(name) {const elements = ['金', '木', '水', '火', '土'];const scores = [];for (let i = 0; i < name.length; i++) {const element = name[i];const index = elements.indexOf(element);if (index !== -1) {scores.push(index + 1);}}const totalScore = scores.reduce((a, b) => a + b, 0);const averageScore = totalScore / scores.length;const五行属性 = elements[Math.floor(averageScore) - 1];return {五行属性:五行属性,五行得分:averageScore.toFixed(2)}; }