0

I have to program a calculator which can calculate a faculty and a eulerian number. these formulars are given:

                       faculty: Number1! = 1*2*...*Number1
                       eulerian number:   Number1
                                       e=    ∑   1/k!
                                            k=0

I have most of the code, but I don't know how to use thes formulars in my code.

<label for="zahl1"></label>
<input id="zahl1" type="text" placeholder="Zahl eingeben">
<label for="zahl2" type="text"></label>
<input id="zahl2" type="text" placeholder="Zahl eingeben"> <br>
<button id="facultyBtn" class="btn btn-info">F</button>
<button id="eulerschBtn" class="btn btn-info">e</button>
document.getElementById("facultyBtn").addEventListener("click", () => {
        const zahl1Input = document.getElementById("zahl1");
        const zahl2Input = document.getElementById("zahl2");
        const zahl1 = Number(zahl1Input.value);
        const zahl2 = Number(zahl2Input.value);
        const F = 

        let ergebnis;
        ergebnis = F

        const ergebnisInput = document.getElementById("ergebnis");

        ergebnisInput.innerText = ergebnis.toString();
    })

    document.getElementById("eulerschBtn").addEventListener("click", () => {
        const zahl1Input = document.getElementById("zahl1");
        const zahl2Input = document.getElementById("zahl2");
        const zahl1 = Number(zahl1Input.value);
        const zahl2 = Number(zahl2Input.value);
        const e = 

        let ergebnis;
        ergebnis = e

        const ergebnisInput = document.getElementById("ergebnis");

        ergebnisInput.innerText = ergebnis.toString();
    })
})

So what I am missing in my code is what to write after "const f =" and "const e =" I would really appreciate some help. I am new to programming, but I have to finish this for school.

gog
  • 10,367
  • 2
  • 24
  • 38
Anna
  • 1
  • 1
  • so, you've written all the code, except the actual implementation of the things you are required to write .... ??? – Bravo Jul 04 '22 at 11:01

1 Answers1

0

This is factorial (faculty), it's a classic:

function faculty(number) {
  total = 1;
  for (var i = 1; i <= number; i++) {
    total = total * i;
  }
  return total;
}
console.log (faculty(3))

As for eulerian number this is from geek4geeg.

function eulerian(n, m) {
  if (m >= n || n == 0)
    return 0;

  if (m == 0)
    return 1;

  return (n - m) * eulerian(n - 1, m - 1) +
    (m + 1) * eulerian(n - 1, m);
}

console.log(eulerian(4, 2))
IT goldman
  • 14,885
  • 2
  • 14
  • 28