top of page

Interval-function

This car is ----> 

. . .

STOP
Play
CODE
improved CODE

working code ---> improved code

CODE

CLOSE.png

var i = 0

var myTimerValue = 3000

var myArray = ["fast", "expensive", "useful", "a womanizer", "super-fast", "economic", "a monster"]

var myVar = setInterval(myFunction, myTimerValue);


 

$w.onReady(function () { })

 

export function BTNplay_click(event) {myFunction()}

export function BTNstop_click(event) {stopFunction()}

 

function myFunction() {

    if (myArray[i]===undefined) {$w('#text1').text="END", stopFunction(), console.log("Function stopped")}

    return $w('#text1').text=myArray[i], i = i+1}

 

function stopFunction() {clearInterval(myVar);}

improved-CODE

CLOSE.png

var i = 0 

var counter=0

var myTimerValue = 3000

var myArray = ["fast", "expensive", "useful", "a womanizer", "super-fast", "economic", "a monster"]

let myVar = setInterval(myFunction, myTimerValue);

 

$w.onReady(function () { })

 

export function BTNplay_click(event) {$w('#BTNstop').enable(), myVar = setInterval(myFunction, myTimerValue);}

export function BTNstop_click(event) {$w('#text1').hide('fade'); $w('#BTNstop').disable(), stopFunction(), setTimeout(()=>{myVar},100)}

 

function myFunction() {console.log(counter++)

    $w('#text1').hide()

    $w('#text1').show('fade')

    $w('#BTNstop').enable()

    if (myArray[i]===undefined) { i = 0,

     $w('#text1').text="END", stopFunction(), console.log("Function stopped")

     setTimeout(()=>{myVar = setInterval(myFunction, myTimerValue)},2000)

 

    }

    else {

        return $w('#text1').text=myArray[i], i = i+1} $w('#BTNstop').disable()}

 

function stopFunction() {clearInterval(myVar);}

bottom of page