BUILDING A LOVE CALCULATOR WITH JAVASCRIPT

avatar
(Edited)
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, 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

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

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

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

Screenshot 2022-08-04 125649.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

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



0
0
0.000
5 comments
avatar

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. 
 

0
0
0.000
avatar

This is a fun project and exercise!

0
0
0.000
avatar

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

Thanks for stopping by really appreciate

0
0
0.000
avatar

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

0
0
0.000
avatar

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

0
0
0.000