Skip to main content
Participant
May 16, 2016
Answered

I am trying to generate an arithmetic and geometric series/sequence with JavaScript.

  • May 16, 2016
  • 1 reply
  • 664 views

I am trying to generate an arithmetic and geometric
series/sequence with JavaScript. The thing that makes this challenging is that
I am using user input to determine different parts of the formula I am using to
generate each sequence. I have tried to run the formulas, but I found out i was
running strings through them and not numbers. How do I generate my
sequences/series and still use user input? PS, these are my formulas: (a1 is
first term, d and r are difference/ratio, and n is the nth term)

1.) a1 + d * n  

2.)a1 * r^n

This topic has been closed for replies.
Correct answer David_Powers

User input from a form is always a string. There are several ways to convert a string to a number in JavaScript:

  • pass it as an argument to Number()
  • pass it as an argument to parseInt() (for an integer)
  • pass it as an argument to parseFloat() (for a floating-point number)

1 reply

David_Powers
David_PowersCorrect answer
Inspiring
May 17, 2016

User input from a form is always a string. There are several ways to convert a string to a number in JavaScript:

  • pass it as an argument to Number()
  • pass it as an argument to parseInt() (for an integer)
  • pass it as an argument to parseFloat() (for a floating-point number)