Javascript

Hello everyone. I’m new to the Javascript language and wish to ask for some help please.
I’ve been given a task but I’m unsure how to go about it. I managed to work out how long it’ll take but unsure how to add in the 1% increase.

A man puts £5800 into a bank account to buy a car. The bank account attracts interest of 4% a year.
The price of the car is £6500. But the price goes up by 1% a year!
Assuming that the man does not take out, or add any money, how many years before he can buy the car?
And what would be the price of the car?

image

Hi @dougbegg28 - welcome to the forums! Can you share your code for what you have tried so far? :slight_smile:

I think you want something along the lines of the following:

let balance = 5800
let carPrice = 6500
let years = 0

for(; balance <= carPrice; years++) {
  balance += balance * 0.04
  carPrice += carPrice * 0.01
  console.log(years, balance, carPrice)
}

console.log(`end years ${ years }, end price ${ carPrice }`)
3 Likes

Thank you, sir. I wasn’t sure how to add in the 1% increase and also get the end result.

1 Like