各開きかっこに対応する閉じかっこがあることを確認することが重要です。
あなたのコード:
function creditCheck(income) {
var ans = 100;
if(income>=100);
return("You earn a lot of money! You qualify for a credit card.");
}
else {
return("Alas you do not qualify for a credit card. Capitalism is cruel like that." );
}
次のようにフォーマットする必要があります。
function creditCheck(income)
{
var ans = 100;
// I'm assuming that you mean to compare 'income' with 'ans'
// Notice that I replaced ';' with an opening bracket here
if(income>=ans)
{
return("You earn a lot of money! You qualify for a credit card.");
}
else
{
return("Alas you do not qualify for a credit card. Capitalism is cruel like that." );
}
// And here I've added a closing bracket
}
括弧で形成された条件付きブロック ( などif
) 内に 1 つの操作しかない場合、実際には開き括弧と閉じ括弧は必要ありません。下記参照。
//
function creditCheck(income)
{
var ans = 100;
// See, no more brackets here
if(income>=ans)
return("You earn a lot of money! You qualify for a credit card.");
else
return("Alas you do not qualify for a credit card. Capitalism is cruel like that." );
}