Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 2
Message 1 of 3

Youtube comment generator problem (Jquery and javascript)

Solved! Go to Solution.

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>
2 Replies
Solution
Pilot Lvl 3
Message 2 of 3

Re: Youtube comment generator problem (Jquery and javascript)

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

Ground Controller Lvl 1
Message 3 of 3

Re: Youtube comment generator problem (Jquery and javascript)

 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) + '<br>')
}

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

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