Javascript字母的值 [英] Javascript Values for letters
问题描述
我在Phonegap开发一个应用程序..我的应用程序是基于命理学计算,在我的应用程序中有一个部分,我需要计算字母的值。例如我的名字'Aron'..我需要计算的值,我使用switch case语句,但它是不工作..任何人可以帮助我找出错误。我给我的代码下面。
I am developing an app in Phonegap.. My app is based on numerology calculation, In my app there is a portion where I need to calculate the value of letters. For example my name 'Aron' .. I need to calculate the values, I am using switch case statement for that but it is not working.. can anyone pls help me to find out the error..I am giving my code below.
// curage是当前年龄
// fna是firstname
//curage is current age //fna is firstname
var bbbb;
for(var i=0; i<curage; i++)
{
bbbb+=lettervalue(fna.charAt(i));
}
function lettervalue(var g)
{
var cccc;
switch(g)
{
case a: cccc="1";
break;
case b: cccc="2";
break;
case c: cccc="3";
break;
case d: cccc="4";
break;
case e: cccc="5";
break;
case f: cccc="6";
break;
//till z
}
return cccc;
}
document.getElementById("hbt").value=cccc;
推荐答案
@Jocheved you switch case statment should like like this。 。
里面的参数dont use var
@Jocheved you switch case statment should be like this..
inside argument dont use var
function lettervalue(g)
{
switch(g)
{
case "a": return 1;
case "b": return 2;
case "c": return 3;
case "d": return 4;
case "e": return 5;
case "f": return 6;
default : return 0;
}
}
最后一行像这样。不要将'cccc'更改为'bbbb'
and change the last line like this..instead of 'cccc' change to 'bbbb'
document.getElementById("hbt").value=bbbb;
这篇关于Javascript字母的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!