I’m making a code to execute a Hailstone Sequence and need some help because I’m not sure how to really code it for this sequence, here are the steps for the sequence.
1. Start with any positive integer.2. If that number is odd, then multiply it by three and add one; otherwise, divide it by two.
here is my coding so far:
[CODE]<html>
<head>
<title> Hailstone Sequence </title>
<script type=”text/javascript”>
function Countdown()
// Assumes: document.CountForm.count contains a number
// Results: displays countdown from that number in document.CountForm.Output
{
var count;
count = parseFloat(document.CountForm.count.value); // GET INITIAL VALUE
document.CountForm.Output.value = “”; // CLEAR TEXT AREA
while (count > 0) { // WHILE NOT AT 0,
document.CountForm.Output.value = // DISPLAY COUNT
document.CountForm.Output.value + count + “n”;
count = count – 1; // AND DECREMENT
}
document.CountForm.Output.value =
document.CountForm.Output.value + “STUCK!”;
}
</script>
</head>
<body>
<div style=”text-align:center”>
<form name=”CountForm”>
Start of the sequence: <input type=”text” name=”count” size=4 value=10 />
<br /><br />
<input type=”button” value=”Begin Hailstone Sequence” onClick=”Countdown();” />
<br /><br />
<textarea name=”Output” rows=15 cols=40 wrap=”virtual”></textarea>
</form>
</div>
</body>
</html>