JSFiddle - React, Tailwind, and code Playground

by Mayankgupta688

HTML

<script src="rx.all.js"></script>
<script src="https://npmcdn.com/@reactivex/rxjs@5.0.0-beta.8/dist/global/Rx.umd.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<!DOCTYPE html>

<html>
  <head>
    <title>Creating Custom Observable</title>
  </head>
  
  <body>
    <h3>Random Number Generation:</h3>
    <div id="rand_numbers">
    </div>
  </body>
</html>

JavaScript

var randomNumberGenerator = Rx.Observable.create(function(observer) {
  observer.next(Math.floor(Math.random() * 100));
  observer.next(Math.floor(Math.random() * 100));
  observer.next(Math.floor(Math.random() * 100));
  observer.next(Math.floor(Math.random() * 100));
  observer.next(Math.floor(Math.random() * 100));
  observer.next(Math.floor(Math.random() * 100));
  observer.next(Math.floor(Math.random() * 100));
});

randomNumberGenerator.subscribe(function(value) {
  console.log("Value from the Simple Observable: " + value);
  $("#rand_numbers").append('<b>Random Number: ' + value + "</b><br><br>");
});