# Elevator
This elevator won't let you reach the top of your building. Right?
- Sometimes a solidity contract or library
- This
Elevator
expects to be used from aBuilding
.
TIP
You can use the view
function modifier on an interface in order to prevent
state modifications. The pure
modifier also prevents functions from modifying
the state. Make sure you read Solidity's
documentation (opens new window)
and learn its caveats.
An alternative way to solve this level is to build a view function which returns
different results depends on input data but don't modify state, e.g.
gasleft()
.
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
interface Building {
function isLastFloor(uint) external returns (bool);
}
contract Elevator {
bool public top;
uint public floor;
function goTo(uint _floor) public {
Building building = Building(msg.sender);
if (! building.isLastFloor(_floor)) {
floor = _floor;
top = building.isLastFloor(floor);
}
}
}