Need a javascript random yes no generator example

Hello guys,

I am new in programming and need a working example of a random yes no generator. Any help will be greatly appreciated !
Example of what I am looking for below

https://www.randomyesno.org/
Thanks,

Hi @skarpioners1, well there you got your example. ;-) You can inspect the document by right clicking the wheel and select “inspect element”; in the dev tools, you can then switch to the “sources” panel (or “debugger” in FF) and see the JS files. Here’s the one responsible for the wheel:

https://www.randomyesno.org/js/home.js

And this is the part with the actual random function:

function rotate(){

	var rand=Math.floor(Math.random() * 24);

	rotates+=18000;

	$(".wheel").css("transform","rotate("+(rotates+18000+rand*(360/12)+15)+"deg)");

	setTimeout(function() { showResult(rand); }, 8000);

}

It uses jQuery (those $() function calls in the code), a library that makes it easier to work with the DOM (although it is largely obsolete these days). Anyway just have a look, if you have trouble understanding certain parts we can certainly explain them to you. :-)

1 Like

Somewhat amazingly, there are a few example sites that can be found by searching eg.

http://www.yesnogenerator.com/

Of course, AFAIK, it is not possible to have code that is truly random. That is, if the code was iterated enough times repeated pattern sequences would be observed.

It is possible for code to generate what appears to be random to the extent that as far as many would be concerned they would consider it “random enough”.

Anyway, for something more practical and useful than a digital equivalent of a coin flip, perhaps this tutorial would be more helpful than looking at other sites’ code.

https://medium.freecodecamp.org/creating-a-bare-bones-quote-generator-with-javascript-and-html-for-absolute-beginners-5264e1725f08

1 Like

Thank you, it helped )))

Thanks!!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.