JSFiddle - React, Tailwind, and code Playground

by Ty

HTML

<ul id="results"></ul>

CSS

#results li.pass {
    color: green
}

JavaScript

function array123(theArr){
    
    var theArrLength=theArr.length;
    if(theArrLength < 3) {
        return false;
    }
    for (var i = 0; i < theArrLength; i++) {
        if(theArr[i] === 1 && theArr[i + 1] === 2 && theArr [i + 2] === 3)
        return true;
        
        }
        }
return false;
}


function assert(value, desc) {
    var li = document.createElement('li');
    li.className = value ? 'pass' : 'fail';
    li.appendChild(document.createTextNode(desc));
    document.getElementById('results').appendChild(li);
}

assert(array123([1,1,2,3,1]), 'First test works');
assert(!array123([1,1,2,4,1]), 'Second test works');
assert(array123([1,1,2,3,1]), 'Third test works');
assert(!array123([1,1,2,6,3]), 'Fourth test works');