OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Disabling conflicting code with conditional and a loop

  • Thread starter Thread starter Joe1023
  • Start date Start date
J

Joe1023

Guest
The user is supposed to select an event to attend, but say the user wants to go to an event thats on a Tuesday between 9am-12pm, all other events that conflict with that time during that day need to be disabled and have a text decoration of line-through.

I've tried to loop through the checkboxes already, but what I've tried wont work. Another part of the condition needs to be added (&&) but I'm not sure how to write it.

Heres what I need in the condition:


  1. First, does the activity occur at the same day and time as the activity that was just clicked? We can check this by seeing if the activity label text contains the above day and time variable values.
    1. Second, is the activity different than the activity that was just clicked? We can check this by seeing if the activity label text is not equal to the label text of the activity that was just clicked.'

I believe I have the first part of the condition correct, but every few clicks, it will give me false when it should be true or vise versa.

Code:
for (let i = 0; i < checkboxes.length; i++) {  
    //Loop through checkboxes with checkboxes[i] . 
    //see if the selected checkbox contains the day and time . 
    //if other checkbox texts contain selected day and time, disable .  
    //and use css to add a line through <label> and <input>  
    /*
    ex: if user selects activity with day Tuesday and time 9am-12pm . 
    all other events with the time 9am-12pm on a Tuesday need to be    
    disabled and put a line through.  
    */
    }

    /*
    bottom code needs to go somewhere in loop to compare date.  
    It also needs another condition (&&) to run the condition  
    correctly, I just dont know what it is yet.  

    Here is the study guide I'm using my issue starts on page 5.

    [Google](https://drive.google.com/file/d/1Vw658- 
    9KUiUZ5yHaABvkytC9W2QBYiW_/view) . 
    */
    if (chosenArr.includes(parsedDate)) { . 
    console.log(chosenArr);   
    console.log(parsedDate);   
    console.log(true);   
    return;  
    } else { . 
    console.log(false);  
    } . 

    chosenArr.push(parsedDate);

The console should respond true when two events of the same day and time are clicked and false if the time and day don't match up. Clicking different events will return true when thats not the correct output. If i can figure out the other part of the condition, I might be able to get the right output.

<p>The user is supposed to select an event to attend, but say the user wants to go to an event thats on a Tuesday between 9am-12pm, all other events that conflict with that time during that day need to be disabled and have a text decoration of line-through.</p>

<p>I've tried to loop through the checkboxes already, but what I've tried wont work. Another part of the condition needs to be added (&&) but I'm not sure how to write it.</p>

<p>Heres what I need in the condition: </p>

<ol>
<li><p>First, does the activity occur at the same day and time as the
activity that was just
clicked? We can check this by seeing if the activity label text
contains the above day and
time variable values.</p>

<ol start="2">
<li>Second, is the activity different than the activity that was just
clicked? We can check this
by seeing if the activity label text is not equal to the label text
of the activity that was
just clicked.'</li>
</ol></li>
</ol>

<p>I believe I have the first part of the condition correct, but every few clicks, it will give me false when it should be true or vise versa.</p>

<pre><code>for (let i = 0; i < checkboxes.length; i++) {
//Loop through checkboxes with checkboxes .
//see if the selected checkbox contains the day and time .
//if other checkbox texts contain selected day and time, disable .
//and use css to add a line through <label> and <input>
/*
ex: if user selects activity with day Tuesday and time 9am-12pm .
all other events with the time 9am-12pm on a Tuesday need to be
disabled and put a line through.
*/
}

/*
bottom code needs to go somewhere in loop to compare date.
It also needs another condition (&&) to run the condition
correctly, I just dont know what it is yet.

Here is the study guide I'm using my issue starts on page 5.

[Google](https://drive.google.com/file/d/1Vw658-
9KUiUZ5yHaABvkytC9W2QBYiW_/view) .
*/
if (chosenArr.includes(parsedDate)) { .
console.log(chosenArr);
console.log(parsedDate);
console.log(true);
return;
} else { .
console.log(false);
} .

chosenArr.push(parsedDate);
</code></pre>

<p>The console should respond true when two events of the same day and time are clicked and false if the time and day don't match up. Clicking different events will return true when thats not the correct output. If i can figure out the other part of the condition, I might be able to get the right output.</p>
 

Latest posts

S
Replies
0
Views
1
Safwan Aipuram
S
Top