## Lesson 118 – Creating a BMI Calculator

The challenge in this lesson is to create a function that takes two parameters (weight and height) and use them to calculate body mass index with the formula provided.

This is my solution:

```
function bmiCalculator(weight, height) {
var bmi = weight / (height * height);
return(Math.round(bmi));
}
```

## Lesson 122 – Random Number Generator

You can generate random numbers in Javascript using –

`Math.random();`

The random number that is generated is a 16 decimal place number. It never reaches the number 1 and it can be any number between 0 and 0.9999999999999999.

This code creates dice number generator –

```
//generates a random number
var n = Math.random();
//multiplies the generated number by 6
n = n * 6;
//rounds the new number down and adds 1 to it
n = Math.floor(n) + 1;
//console logs a number between 1 and 6
console.log(n);
```

This code can be shortened to:

```
var n = Math.random();
n = Math.floor(n * 6) + 1;
console.log(n);
```

The challenge in this lesson is to create the code to prompt the user to input his or her name and the name of their potential match and the output to the user an alert telling them the percentage of their match.

This is my solution –

```
var name = prompt("What is your name?");
var match = prompt("What is the name of your love match");
var n = Math.random();
n = Math.floor(n * 100) + 1;
alert(name + " and " + match + " are a " + n + "% match!");
```