BUILDING A LOVE CALCULATOR WITH JAVASCRIPT

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@joebolite97·
0.000 HBD
BUILDING A LOVE CALCULATOR WITH JAVASCRIPT
###### Hey guys its been a while in here, and how has coding been? 
###### I would like to share with you guys what I learnt today. I picked up JavaScript for beginners after I wrote a post on [JavaScript Frameworks](https://peakd.com/hive-169321/@joebolite97/javascript-frameworks-and-types), and I must admit it hasn't been an easy ride.

In this post I will be showing you the logic I  used to make a simple love calculator using JavaScript.
The code are written with chrome developer tools...


![Screenshot 2022-08-04 114218.png](https://files.peakd.com/file/peakd-hive/joebolite97/23vsqueDg7AhEybiNeXpx7pYVZkULowcrk7j723QPsutCJT7hUNTtip5fTjJ4zLJ856jJ.png)

Apparently what I did was I used Math.floor function and Math.random function

*Math.random* is a function that generates random numbers from 0 to 0.9999999, but can't get to 1
 
While *Math.floor* approximates a number to the nearest whole number( it performs this without any regard for the number after the decimal i.e. 4.5 will be approximated to 4 and not 5.

The part where I multiplied by 100 and added +1 is to make sure we have two whole numbers, since we want to approximate the number generated by Math.random we have to multiply by 100, by adding +1 we ensure our answer is never 0.

![Screenshot 2022-08-04 114234.png](https://files.peakd.com/file/peakd-hive/joebolite97/Eo8ZaTRLqqQjgvoTYomPUQUgP5RLefqhjryHtyu18Aw3LcQ4KaHAjpxNqdYW4yVRHKY.png)

I also made use of conditional statements ( if, else if, else) to state the conditions at which a boy and a girl can be compatible,

*I stated **if** the number generated is  less than 30, they **Do not match** , **else if** compatibility test generated is less than 70 but greater than 30, **Give it a Trial**, **else** they are a Perfect Match.*

I made use of prompt() to display an input to type in the boy and girl's name and alert() to state their compatibility result. 

![Screenshot 2022-08-04 123308.png](https://files.peakd.com/file/peakd-hive/joebolite97/23tcNhoPzQdR8LvDUktyUqA35gUd7aMLbYr8Ux674SsbLWPqq2GN9eJGRgRhsiVmr9KZU.png)

A pop is going to show like  this, where you can input your name


![Screenshot 2022-08-04 125649.png](https://files.peakd.com/file/peakd-hive/joebolite97/23u6YrC5UKS1Tn85Pfvt6zxT9j67oNTB9X7PuHCqTsLeUmYQpCRsmeYjtvMp1k4avA8WF.png)


An alert will then show like this,  stating your compatibility

Thanks for stopping by,  ensure to try out this code and input your friends names, Fun! isn't😃
![text16.png](https://files.peakd.com/file/peakd-hive/joebolite97/246FZMwteQQMEgT4iDyeTv2vw9QqRZ9UhFG7im6TzvjxJG9Je1D8LFuYrZk8PwdbbPNBm.png)

I hope this was helpful...
Until time, 
Stay woke✌️
*All images and codes were taken and written by me*
👍 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,