# BUILDING A LOVE CALCULATOR WITH JAVASCRIPT

in Programming & Dev2 years ago (edited)
###### 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, 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...

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.

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.

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

Thanks for stopping by, ensure to try out this code and input your friends names, Fun! isn't😃

Until time,
Stay woke✌️
All images and codes were taken and written by me

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support.

This is a fun project and exercise!

Yeah it's really fun...
Especially when you start inputting your friends names a seeing funny results

Thanks for stopping by really appreciate

Right?! I am going to try this out when I have free time.

I would be glad to hear your response, when you have tried it.