#[SWIFT] Vexing vehicle purchase

3 messages · Page 1 of 1 (latest)

frosty iris
#

Hello, I've passed 2/3 tests for this problem.
Code snip

func canIBuy(vehicle: String, price: Double, monthlyBudget: Double) -> String {
   let emiPrice = price/12
  if emiPrice <= monthlyBudget{
      return "Yes! I'm getting a \(vehicle)"
  }
    else if emiPrice > monthlyBudget && emiPrice <= (monthlyBudget + monthlyBudget*10/100)
    {
        return "I'll have to be frugal if i want a \(vehicle)"
    }
    else{
        return "Darn! No \(vehicle) for me"
    }
}

func licenseType(numberOfWheels wheels: Int) -> String {
  if wheels == 2 || wheels == 3{
      return "You will need a motorcycle license for your vehicle"
  } else if wheels == 4 || wheels == 6 {
      return "You will need an automobile license for your vehicle"
  } else  if wheels == 18 {
      return "You will need a commercial trucking license for your vehicle"
  } else {
      return "We do not issue licenses for those types of vehicles"
  }
}

func calculateResellPrice(originalPrice: Int, yearsOld: Int) -> Int {
  if yearsOld < 3{
      return originalPrice * 80/100
  } else if yearsOld >= 3 && yearsOld < 10 {
      return originalPrice * 70/100
  } else {
      return originalPrice * 50/100
  }
}

i failed the 3rd test for the first function. It's supposed to return a statement according to whether the vehicle is within budget, 10% more than budget or more than 10%.
the test i failed shows

try XCTSkipIf(true && !runAll)  // change true to false to run this test
XCTAssertEqual(
  canIBuy(vehicle: "2020 Indian FTR 1200", price: 12_500, monthlyBudget: 200),
  "I'll have to be frugal if I want a 2020 Indian FTR 1200")
testBeFrugal : XCTAssertEqual failed: ("Darn! No 2020 Indian FTR 1200 for me") is not equal to ("I'll have to be frugal if I want a 2020 Indian FTR 1200") 

is the test case wrong? because 12500 and 200 would result in more than 10% increase from budget

viscid jetty
#

You're not supposed to be paying off the entire vehicle cost in one year.

frosty iris