gpt4 book ai didi

Javascript - 重复字符

转载 作者:行者123 更新时间:2023-11-28 09:55:32 26 4
gpt4 key购买 nike

我正在尝试创建一个程序来重复输入的单词的次数与它包含的字符一样多,我尝试了几种不同的方法,但都不起作用,这是迄今为止的工作。

<html>
<head>
<title>Repeat Word</title>
<script type="text/javascript">
//Program: Repeat Word
//Purpose: Repeat word for as many times as it has characters
//Date last modified: 4/11/12
var word = "";

word = prompt("Enter the word you would like repeated?")


</script>
</head>
<body>
</form>
</body>
</html>

我希望它重复“hello”的一个例子是......

Enter a word: Hello

Hello

Hello

Hello

Hello

Hello

最佳答案

只需添加以下内容:

for(var i = 0, repeat = word.length; i < repeat; i++) {
console.log(word);
}

关于Javascript - 重复字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10106207/

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