# How to count a number as a geometric sequence/progression

## Recommended Posts

This is the closest I got;

```
<input type="number" id="exmp" value="1">
<button onclick="myExample()">Convert</button>

<p id="exmpone1"></p>

<script>
function myExample() {
var no = document.getElementById("exmp").value;
document.getElementById("exmpone1").innerHTML = Math.pow(no, no);
}
</script>```

Edited by Winston
##### Share on other sites

Here is an update. I was continuing to try to find it, https://www.geeksforgeeks.org/program-to-print-gp-geometric-progression/ was similar, but I want it to be variable, and show final number without all numbers from 1 up. When I tried to type 5 in the code, and have the ratio of 2 (if I am not mistaken), it shows, "1, 2, 4, 8, 16", but I just want the "16" when I change it.

I tried this, https://www.30secondsofcode.org/js/s/geometric-progression and again, set the ratio to 2, but it only shows numbers that match in the code, where if I write 8, it would read, "1,2,4,8".

I'm still not having any luck, so please respond and help. I don't know why they just make "Math.GP", which would be easier.

##### Share on other sites

The reason you're finding code that prints all of the terms up to N is because that is what a progression is: a sequence of terms.

Math.pow() already provides everything you need to find any one term in a geometric progression, which is why browsers will never implement a more specific function to do it. If browsers had a dedicated built-in function for every single little problem somebody wanted to solve there would be millions of them.

The formula for a term is right on the page you linked to:

`TN = a1 * r(n-1)`

The code is simple:

```function geometricProgression(a1, r, n) {
return a1 * Math.pow(r, n-1);
}```

Putting into the HTML with the inputs and outputs it would look like this:

```Progression factor: <input type="number" id="factor" value="2"><br>
Term number: <input type="number" id="term" value="1">
<button onclick="myExample()">Convert</button>

<p id="exmpone1"></p>

<script>
function myExample() {
var factor = Number(document.getElementById("factor").value);
var term = Number(document.getElementById("term").value);
document.getElementById("exmpone1").innerHTML = geometricProgression(factor, factor, term);
}

function geometricProgression(a1, r, n) {
return a1 * Math.pow(r, n-1);
}
</script>```

##### Share on other sites

Thank you, it helped me make the file work, and helped move to the correct topic (don't know how to do that manually)... But now I face a new problem. Though I did convert the HTML to EXE, I've been trying for a few hours now to convert this HTML to APK. I tried converting the HTML straight over to the XML in an APK app, and I tried converting an EXE to APK. One app gave me (and others, frustratingly,) a message; "Wrong! Select a destination folder correctly...". One site, trying to convert HTML to APK, I could not import pictures. I looked for a way to convert from CSS and other things to it like APK, no luck, "You can't convert xxx to yyy. Meant for a different platform." Well, could you try to convert this HTML to APK for me, or show me how to rewrite the commands?

```<!DOCTYPE html>
<html>
<title>Son Of A Pitch 2! - Sound Frequency Converter</title>
<style>
body {
background-image: url("BackGround.png");
background-repeat: repeat;
background-attachment: fixed;
background-position: center;
background-size: 100% 100%;
}
</style>
<body>
<audio id="tappingone">
<source src="ButtonClick.WAV" type="audio/wav">
</audio>
<audio id="tappingtwo">
<source src="ButtonHover.WAV" type="audio/wav">
</audio>
<h2>Winston presents...</h2>
<img src="Logo.png" width="500" height="500"><br>
Type the octave <input type="number" id="term" value="0"> and
<button onclick="myExample();myTapClickAud();" onmouseover="myOverClickAud();" onmouseleave="myClickOffClickAud();">convert</button> to the units...

<p id="exmpone1">With this page, you can convert sound frequencies to other compatible units.</p>
<p id="exmpone2">We will be using 1 Hertz to represent note C0. The higher the number, the higher the frequency, and lower or negative numbers will lower the frequency.</p>
<p id="exmpone3">This is an updated version of the original S.O.A.P. which could barely do Hertz, now upgraded to work better thanks to a user helping and giving me programming code.</p>
<p id="exmpone4">So? What are you waiting for? Enter a number and convert!</p>
<p id="exmpone5"><br>Last updated on Thursday, July 15, 2021, 12:57 PM</p>
<p id="exmpone6"><br><br><b>Missing a frequency and&#x002F;or pitch unit? Report incorrect information? Errors and&#x002F;or technical difficulties? Don't scrub your cassette tape off, but instead, please contact me and tell me what is wrong...</b></p>
<p id="exmpone8"></p>
<p id="exmpone9"></p>
<p id="exmpone10"></p>
<p id="exmpone11"></p>
<p id="exmpone12"></p>
<p id="exmpone13"></p>

<script>
var one = document.getElementById("tappingone");
var two = document.getElementById("tappingtwo");
function myTapClickAud() {
one.play();
one.currentTime = 0;
two.pause();
}
function myOverClickAud() {
one.pause();
two.play();
two.currentTime = 0;
}
function myClickOffClickAud() {
two.pause();
}
function myOffClickAud() {
one.pause();
two.pause();
}
function myExample() {
var term = Number(document.getElementById("term").value);
document.getElementById("exmpone1").innerHTML = geometricProgression(1, 2, term)*2 + " Hertz";
document.getElementById("exmpone2").innerHTML = geometricProgression(1, 2, term)/1000*2 + " Kilohertz";
document.getElementById("exmpone3").innerHTML = term + " Octaves";
document.getElementById("exmpone4").innerHTML = term*1200 + " Cents";
document.getElementById("exmpone5").innerHTML = term*12 + " Semitones";
document.getElementById("exmpone6").innerHTML = term*5 + " Sharp&#x002F;Flat Notes (Black Keys)";
document.getElementById("exmpone7").innerHTML = term*7 + " Natural Notes (White Keys)";
document.getElementById("exmpone8").innerHTML = geometricProgression(1, 2, term)/1000000000*2 + " Gigahertz";
document.getElementById("exmpone9").innerHTML = geometricProgression(1, 2, term)/1000000*2 + " Megahertz";
document.getElementById("exmpone10").innerHTML = geometricProgression(1, 2, term)/1000000000000*2 + " Terahertz";
document.getElementById("exmpone11").innerHTML = geometricProgression(1, 2, term)/10*2 + " Decahertz";
document.getElementById("exmpone12").innerHTML = geometricProgression(1, 2, term)/100*2 + " Hectohertz";
document.getElementById("exmpone13").innerHTML = 1 / geometricProgression(1, 2, term)/2 + " Second Cycles";
}
function geometricProgression(a1, r, n) {
return a1 * Math.pow(r, n-1);
}
</script>
</body>
</html>```

I have the pictures and sounds, but that probably would be stored in "Resources/drawable". What app could I use to turn it into an APK Android Application?

##### Share on other sites

I've never made an app for Android so I can't answer that.

If I intended to build an app, I would download Android Studio and build it there.