Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript Can anyone help me in this coding

Jana

New Coder
Task : Counter Timing Validation Check
When Registering new counters we need to check the time validation
The following fields must be validated
Counter Start Time : 9am
Counter End Time : 6pm
Counter Break Start Time : 1pm
Counter Break End Time : 2pm

#1. Counter End Time should be Greater than Counter Start Time
#2.Counter Break Time should be within the Counter start and end time
#3.Counter Break End Time should be Greater than Counter Break Start Time
#4. AM/PM must be taken into account for validation.
 
I can think of a few ways of doing this, but will use an array for this example.
Grab the numbers in this order: Counter Start Time, Counter Break Start Time, Counter Break End Time, Counter End Time.
As each number is obtained check to see if it's AM or PM ( I would use checkboxes for that). If PM add 12 to the number.
Then using the PUSH method add them to the array( You make the array at step one of the SCRIPT).
Now we check the smallest number and see if it's the element we want and then eliminate it from the array.
EXAMPLE:
JavaScript:
const arr = [];
IF(Counter Start Time = Math.min(...arr){
   arr = arr.shift(arr); //Removes the first element of the array
}else{
    document.getElementById("demo").innerHTML = "Did not evaluate";
}

if(Counter Break Start Time= Math.min(...arr){    // And so on.....

If you're going to use hours, minutes, seconds you will need a function to convert everything to seconds.

You should also check for duplicates in the array.
 
Last edited by a moderator:

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom