Youtube comment generator problem (Jquery and javascript)

Hi, i have problem, i’m trying to write and program which will be genereting a something like this from prompt:

t

te

tes

test

tes

te

t

And i’ve done this. It work in console, but now i want to display it on the page. I know a little about JQuery, but i don’t know how to do that. Thanks for helping…

<!DOCTYPE html>
<html>
<head>
<title>Generator</title>
</head>
<body>
<h1 id="testing">Hello world!</h1>
<script src="https://code.jquery.com/jquery-2.1.0.js"></script>
<script>

var string = prompt ("Wpisz zdanie do przekonwertowania");
var text = string;
for (i = 0; i < text.length - 1; i++) {
	console.log(text.slice(0,i))
}

for (i = 0; i < string.length; i++) {
	var text = text.substring(0, text.length-1);
	console.log(text);
}


</script>
</body>
</hmtl>

Your javascript needs to generate HTML content to appear in the web page. Here is a possible related tutorial.

1 Like

 I’ve changed your code a bit. I replaced console.log with a document.write and made some changes to the first loop.

<!DOCTYPE html>
<html>
<head>
<title>Generator</title>
</head>
<body>
<h1 id="testing">Hello world!</h1>
<script src="https://code.jquery.com/jquery-2.1.0.js"></script>
<script>

var string = prompt ("Wpisz zdanie do przekonwertowania");
var text = string;
for (i = 0; i < text.length + 1; i++) {
	document.write(text.substring(0, i) + '
')
}

for (i = 0; i < string.length; i++) {
	var text = text.substring(0, text.length -1);
	document.write(text + '
');
}

</script>
</body>
</hmtl>