使用我们免费的宝宝起名宝典,为您的宝宝找到完美的中文名字。输入以下信息,我们会根据姓名评分、五行属性、吉祥度和音律美感对您的姓名进行评分。
男
女
const form = document.getElementById('name-form');form.addEventListener('submit', (event) => {event.preventDefault();const lastName = document.getElementById('last-name').value;const firstName = document.getElementById('first-name').value;const gender = document.getElementById('gender').value;const resultContainer = document.getElementById('result-container');// 计算姓名评分const score = calculateScore(lastName, firstName, gender);// 显示结果const resultHtml = `
评分 | 五行属性 | 吉祥度 | 音律美感 |
---|---|---|---|
${score.total} | ${score.elements} | ${score.auspiciousness} | ${score.phonetics} |
`;resultContainer.innerHTML = resultHtml;});function calculateScore(lastName, firstName, gender) {// 初始化评分const score = {total: 0,elements: '',auspiciousness: 0,phonetics: 0};// 计算姓氏和名字的笔画数const lastNameStrokes = getStrokes(lastName);const firstNameStrokes = getStrokes(firstName);// 计算姓名评分score.total = lastNameStrokes + firstNameStrokes;// 计算五行属性score.elements = getElements(lastName, firstName);// 计算吉祥度score.auspiciousness = getAuspiciousness(lastName, firstName);// 计算音律美感score.phonetics = getPhonetics(lastName, firstName);return score;}function getStrokes(name) {// 初始化笔画数let strokes = 0;// 循环遍历每个字符并计算笔画数for (let i = 0; i < name.length; i++) {const char = name[i];strokes += getCharStrokes(char);}return strokes;}function getElements(lastName, firstName) {// 初始化五行属性let elements = '';// 根据姓氏和名字的最后一个字符确定五行属性const lastNameElement = getCharElement(lastName[lastName.length - 1]);const firstNameElement = getCharElement(firstName[firstName.length - 1]);// 组合五行属性elements = lastNameElement + firstNameElement;return elements;}function getAuspiciousness(lastName, firstName) {// 初始化吉祥度let auspiciousness = 0;// 循环遍历每个字符并计算吉祥度for (let i = 0; i < lastName.length; i++) {const char = lastName[i];
auspiciousness += getCharAuspiciousness(char);}for (let i = 0; i < firstName.length; i++) {const char = firstName[i];auspiciousness += getCharAuspiciousness(char);}return auspiciousness;}function getPhonetics(lastName, firstName) {// 初始化音律美感let phonetics = 0;// 循环遍历每个字符并计算音律美感for (let i = 0; i < lastName.length; i++) {const char = lastName[i];phonetics += getCharPhonetics(char);}for (let i = 0; i < firstName.length; i++) {const char = firstName[i];phonetics += getCharPhonetics(char);}return phonetics;}// 获取单个字符的笔画数function getCharStrokes(char) {const strokesMap = {'一': 1,'丨': 1,'丿': 1,'乙': 2,'亅': 1,'二': 2,'丁': 2,'七': 2,'长': 3,'八': 3,'卜': 3,'三': 3,'凡': 3,'五': 4,'六': 4,'冗': 4,'九': 4,'十': 4,'夫': 4,'之': 4,'人': 4,'儿': 4,'入': 4,'八': 4,'口': 5,'刀': 5,'夕': 5,'大': 5,'王': 5,'兀': 5,'日': 5,'早': 5,'月': 5,'木': 6,'平': 6,'木': 6,'本