+ 1

How can I get to write code on consecutive value that are increasing and make number of counts

Assuming we have a randomly selected numbers between 1-100, and at every 1 seconds interval A random number is selected and printed out Now from the randomly out value, I want to get alert when output value increases consecutively for specific number of times like example below Alert on 5 numbers of consecutively increasing numbers below #1- 23 #2- 31 #3- 38 #4- 45 #5 - 67 ---- alert goes off here #6 - 54 How do I get to write code for this example! I need help I just started learning Coding: JavaScript Will appreciate any help I can get! Thanks in advance

31st May 2022, 12:25 AM
Faith Adewale Onasoga
3 ответов
+ 4
One way is to always store last number, compare to the next, then increment counter if next > last, or zero it otherwise. Start in Code Playground and link your code in the question description. Also, it would be nice if you remove the junk tags, leaving only JavaScript and other eventually useful ones.
31st May 2022, 12:38 AM
Emerson Prado
Emerson Prado - avatar
+ 1
This is a good practise for beginner to learn to code. Firstly, you can form the functions you require to write, each one setting up the test inputs and the expected output. You would need the following functions 1. function randomGen(startRange, endRange) testing inputs, startRange= 1, endRange=100 expected output = integer between 1 to 100 2. function isUpSequence(totalSet, testingArray) testing inputs, totaalSet=5, testingArray= [10,21,32,42,59]; expected output = true; testing inputs, totaalSet=5, testingArray= [98,21,32,42,59]; expected output = false; 3. function insertNewNumber(bufferArray, newNumber) testing input, newNumber=23, bufferArray=[] expected output = [23] testing input, newNumber=15, bufferArray=[23] expected output = [23,15] testing input, newNumber=56, bufferArray=[23,15] expected output = [23,15,56] testing input, newNumber=10, bufferArray=[23,15,56,2] expected output = [23,15,56,2,10] testing input, newNumber=68, bufferArray=[23,15,56,2,10] expected output = [15,56,2,10,68] ..
31st May 2022, 6:37 AM
Calviղ
Calviղ - avatar
+ 1
<continue from previous message> Form the above functions first, and try to write logic in the functions to meet the expected output. For beginners starting to learn to code, it's important that you have a good approach that really guides you to write good codes, right from the start. I am showing here a good method you can follow that will enable you to understand and write unit tests, and guide you through eventual learning of an important software development process called Test Driven Develpment (TDD).
31st May 2022, 6:37 AM
Calviղ
Calviղ - avatar