Challenge 23

🔢

Is Integer?

Open in Code Editor or Copy Instructions
...solutions at bottom of page...

Create a function which takes in a number as a parameter and returns whether it is an integer or not

Examples:

isInteger(4) returns true

isInteger(4 ** 2) returns true

isInteger(4.1) returns false

Extension:

Output the magnitude away from the closest integer the real part of the number is - e.g. 4.1 could output "4.1 is 0.1 away from 4", while 4.7 would output "4.7 is 0.3 away from 5". This should also work for negative numbers too

Solutions

IGCSE 0478 / O-Level 2210 A-Level 9618