DEV Community

superDebutante
superDebutante

Posted on

help for an exercice RXJS

hi everyone,
someone could help me with the end of this programm?
i need to stop the runner when he cross the arrival line so we paly the jingle an we switch to mode2
thansks you for your help

<!DOCTYPE html>





RX Demo

<br>

<div class="highlight"><pre class="highlight plaintext"><code> pre {
border: 1px solid black;
}
&lt;/style&gt;
</code></pre></div>
<p></head></p>

<p><body><br>
<input type="text"></input><button>Go</button><br>
<section><br>
</section><br>
<script></p>
<div class="highlight"><pre class="highlight plaintext"><code> const sorties = [];

const sectionSorties = document.currentScript.previousElementSibling;

for (var i = 0; i &amp;lt; 5; i++) {
    const elt = document.createElement("pre");
    sorties.push(elt);
    sectionSorties.appendChild(elt);
}

var input = rxjs.fromEvent(document.querySelector('input'), 'input');

input.subscribe(evt =&amp;gt; sorties[0].innerHTML += evt.data);

input.pipe(

    rxjs.operators.filter(evt =&amp;gt; evt.target.value.length &amp;gt; 4)

    , rxjs.operators.map(evt =&amp;gt; evt.target.value)
)
    .subscribe(val =&amp;gt; sorties[1].innerHTML = val);
    rxjs.operators.delay(10000)

    , rxjs.operators.throttleTime(5000)
    , rxjs.operators.map(evt =&amp;gt; evt.data.toUpperCase()))
    .subscribe(value =&amp;gt; sorties[2].innerHTML += value);
var click = rxjs.fromEvent(document.querySelector('button'), 'click');
click.subscribe(function (evt) { sorties[0].innerHTML = ""; });
input.pipe(
    rxjs.operators.takeUntil(click) 
    , rxjs.operators.map(evt =&amp;gt; evt.target.value)
)
    .subscribe(value =&amp;gt; sorties[3].innerHTML = value);
rxjs.merge(
    input.pipe(rxjs.operators.map(evt =&amp;gt; evt.target.value.length))
    , click.pipe(rxjs.operators.map(evt =&amp;gt; " * "))
)
    .subscribe(value =&amp;gt; sorties[4].innerHTML = value);
Enter fullscreen mode Exit fullscreen mode

&lt;/script&gt;
</code></pre></div>
<p></body></p>

<p></html></p>

Top comments (0)