All tasks

Snickers Change

Snickers Change

Imagine you walk into a store (like ATB or Fora), and at the checkout you suddenly really want a Snickers!

You have 200 UAH in your pocket, and you decide to go all in and spend all of it.

How many Snickers can you buy with that money, and how much change will you get back? Let’s figure it out!

Starting data

  1. Copy this function and don’t change it:
/** function that counts how many Snickers you can get */
function countSnikers(sum, price) {
    
}
  1. Do all the calculations inside the function.
  2. But keep all the console.logs outside the function.
  3. Print the result to the console in this format:
I can afford Snickers: 7 pcs
Change: 10 UAH