Skip to content Skip to sidebar Skip to footer

Making A Calculation For A Modal Using Coffeescript

I am trying to make it so a user can input 3 numbers and when they click the submit button they will see a modal with the calculations from these 3 numbers within the modal. I am u

Solution 1:

class Calculation
  constructor (@price, @mortgage, @rent) -> 
  monthly_savings -> @mortgage - @rent
  savings_goal -> @price * 0.03
  months -> Math.ceil @savings_goal / @monthly_savings
  savings -> monthly_savings * months

And to create the calculaction instance:

price = document.getElementsByName('house_amount')[0].value
mortgage = document.getElementsByName('high_rent')[0].value
rent = document.getElementsByName('current_rent')[0].value
instance = new Calculation(price, mortgage, rent)

Then to display it somewhere:

document.getElementById('total_savings').value = instance.savings();

Post a Comment for "Making A Calculation For A Modal Using Coffeescript"