How do we write a javascript which asks a user to submit a number. The series is afterwards upheld in to a duty we write which contains a loop. The double back will double back a series we upheld in to a duty as well as imitation out a word “ha” which most times. For instance, if we entered 3, a duty would imitation out “ha ha ha”? Any assistance would be GREATLY appreciated!
Here’s a couple of trivial alternatives that differ by how the user gives input…
<html>
<head>
<style>
#showHa { font-size: 1.5em; }
</style>
<script>
// utility cover function
function get(eid) {return document.getElementById( eid ); };
// get user input and display math operations on it
function showHa() {
// try to evaluate as a number
var num = parseInt( get( ‘num’ ).value );
// if not a valid number, advise user and exit
if (isNaN(num) || num <= 0) {
alert( ‘not a valid positive integer’ );
return;
}
// since we didn’t exit above, clear display and use number
get( ‘showHa’ ).innerHTML = ”;
for (var i = 0 ; i < num; i++) {
get( ‘showHa’ ).innerHTML += ‘ha ‘;
}
}
</script>
</head>
<body>
<form>
enter a positive integer: <input type="text" id="num" />
<input type="button" value="click" onclick="showHa();" />
</form>
<p id="showHa"></p> <!– ha will go here –>
</body>
</html>
<html>
<head>
<style>
#showHa { font-size: 1.5em; }
</style>
<script>
// utility cover function
function get(eid) {return document.getElementById( eid ); };
// get user input and display math operations on it
function showHa(n) {
// try to evaluate as a number
var num = parseInt( n );
// if not a valid number, advise user and exit
if (isNaN(num) || num <= 0) {
alert( ‘not a valid positive integer’ );
return;
}
// since we didn’t exit above, clear display and use number
get( ‘showHa’ ).innerHTML = ”;
for (var i = 0 ; i < num; i++) {
get( ‘showHa’ ).innerHTML += ‘ha ‘;
}
};
function doHa() {
showHa( prompt( ‘enter a positive integer’, ” ) );
};
window.onload = doHa;
</script>
</head>
<body>
<p id="showHa"></p> <!– ha will go here –>
</body>
</html>