23_number_flats.js 515 B

12345678
  1. let floorsInTheHouse = 9;
  2. const numberOfApartmentsPerFloor = 4;
  3. let apartmentNumber = +prompt('Укажите номер квартиры');
  4. let entranceNumber = Math.ceil(apartmentNumber / (floorsInTheHouse * numberOfApartmentsPerFloor));
  5. let floorNumber = Math.ceil((apartmentNumber % (floorsInTheHouse * numberOfApartmentsPerFloor)) / numberOfApartmentsPerFloor);
  6. alert(`Номер подезда - ${entranceNumber}, этаж = ${(floorNumber === 0) ? (floorNumber = floorsInTheHouse) : floorNumber}`);