Untitled
unknown
html
4 years ago
1.4 kB
13
Indexable
<!DOCTYPE html> <html> <head> <title>Paper Folding Puzzle</title> <script type="text/javascript"> function FoldUntil(){ var count, dist, thick, str count = 0; dist = parseFloat(document.getElementById('goalBox').innerHTML)* 5280 * 12; thick = parseFloat(document.getElementById('thickBox').innerHTML); while(thick < dist) { thick = thick * 2; count ++; } str = "Total number of folds to reach Sun: " + count; document.getElementById("outputDiv").innerHTML += str; } // declare variables // extract value from 'thickBox' // extract value from 'goalBox' // convert goal miles to goal inches // initialize counter for number of folds // set up while loop to continue 'folding' until // the thickness is at least the number of required goal inches. // note that the thickness is doubled each time a fold is made. // be sure to increment number of folds each time another fold is made // display the number of folds needed </script> </head> <body> <p> Initial paper thickness (in inches): <input type="text" id="thickBox" size="8" value="0.002"> <br> Goal distance (in miles): <input type="text" id="goalBox" size="10" value="93000000"> </p> <input type="button" value="Fold Until Goal" onclick="FoldUntil();"> <hr> <div id="outputDiv"></div> </body> </html>
Editor is loading...