gpt4 book ai didi

javascript - 无法调用函数

转载 作者:行者123 更新时间:2023-12-02 20:14:36 24 4
gpt4 key购买 nike

请参阅本文底部;

function isVowel(aCharacter)
{
return ((aCharacter == 'a') || (aCharacter == 'A')||
(aCharacter == 'e') || (aCharacter == 'E')||
(aCharacter == 'i') || (aCharacter == 'I')||
(aCharacter == 'o') || (aCharacter == 'O')||
(aCharacter == 'u') || (aCharacter == 'U')||
(aCharacter == 'y') || (aCharacter == 'Y'));
}


function myF(aString)
{
// variable to hold resultString
var resultString = '';

// variable to hold the current and previous characters
var currentCharacter = '';
var precedingCharacter = '';

// in the case of the first character in the string there is no
// previous character, so we assign an empty string '' to the variable at first
//precedingCharacter = '';

// TODO part (ii)
// add code as directed in the question

var i = 0;
for( i; i < sString.length; ++i)
{

currentCharacter = sString.charAt(i);
if (isVowel(currentCharacter) && (!isVowel(precedingCharacter)))
{
resultString = resultString + 'ub';
}
resultString = resultString + currentCharacter;
precedingCharacter = currentCharacter;
}

return resultString;
}

var string1 = "the cat sat on the mat";
var result1 = myF(string1);
document.write(string1);//THIS ISN'T GOING TO BE DISPLAYED, BUT WHY?

document.write('<BR>');
document.write(result1);

最佳答案

您迭代的是不存在的 sString,而不是您的参数 aString

关于javascript - 无法调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6491850/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com