What’s wrong here:
function randomWholeNum() {
// Only change code below this line.
var random = Math.random();
var totalRandom = random * 10;
var floor = Math.floor(totalRandom);
return floor;
}
What’s wrong here:
function randomWholeNum() {
// Only change code below this line.
var random = Math.random();
var totalRandom = random * 10;
var floor = Math.floor(totalRandom);
return floor;
}
Your code will sometimes generate 0 which is not a whole number. Fixing the problem is up to you.
I just wrapped your function into an html
<html>
<head>
<script language="javascript">
function randomWholeNum() {
// Only change code below this line.
var random = Math.random();
var totalRandom = random * 10;
var floor = Math.floor(totalRandom);
document.getElementById("randomNum").value=floor;
return floor;
}
</script>
</head>
<body>
<input type="button" onclick="randomWholeNum()" id="randomNum" />
</body>
</html>
Just that zero also gets returned, which is also a valid random whole number.
If you do not need that, then increment floor before returning.
I don’t think there’s anything wrong with your logic, but I think the challenge wants your code to look like the one in the example (like Math.random() * 10
instead of doing it in two lines).
Stranger still, your code won’t pass if you removed the example code
(this line:
var randomNumberBetween0and19 = Math.floor(Math.random() * 20);
)