FCC Random - parseInt
by vanduzled
JavaScript
function randomFraction() {
// Only change code below this line
return Math.random();
// Only change code above this line
}
console.log(randomFraction());
//0.2304661832910586
// Math.random() can return a 0 but never return a 1.
function randomWholeNum() {
// Only change code below this line
return Math.floor( Math.random() * 10 );
}
console.log(randomWholeNum());
// Use this technique to generate and return a random whole number between 0 and 9.
// 2, 6
function randomRange(myMin, myMax) {
// Only change code below this line
return Math.floor( Math.random() * (myMax - myMin + 1)) + myMin;
// Only change code above this line
}
console.log(randomRange(1, 5));
// Create a function called randomRange that takes a range myMin and myMax and returns a random whole number that's greater than or equal to myMin, and is less than or equal to myMax, inclusive.
function convertToInteger(str) {
return parseInt(str);
}
convertToInteger("56");
console.log(convertToInteger("56"));
//Use the parseInt Function with a Radix
function convertToInteger(str) {
return parseInt(str, 2);
}
convertToInteger("10011");
console.log(convertToInteger("10011"))
//19