Hi !
I don’t know how to format error messages.
Exercise : Dart/Nth Prime
My code :
class NthPrime {
int prime(int n) {
if (n < 1) {
throw ArgumentError(
'message', 'Invalid argument(s): There is no zeroth prime');
}
List<int> primes = [];
int counter = 2;
while (primes.length < n) {
if (primes.any((p) => counter % p == 0)) {
counter++;
} else {
primes.add(counter);
}
}
return primes.last;
}
}
did not pass the tests :
NthPrime there is no zeroth prime [E]
Expected: throws <Instance of 'ArgumentError'> with `message`: 'Invalid argument(s): There is no zeroth prime'
Actual: <Closure: () => int>
Which: threw ArgumentError:<Invalid argument(s) (Invalid argument(s): There is no zeroth prime): message>
What is wrong ?