Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Joseph Escobedo
seal-mask
.a{fill-rule:evenodd;}techdegree
Joseph Escobedo
Full Stack JavaScript Techdegree Student 4,172 Points

Filtering out corresponding events in Unit 3 project

I've looped through each checkbox input and now I'm trying to test to see if the checked checkbox contains the same date and time as other events. From there I want to filter the other events out so the user cant access events with the same time and date.

At the moment I get an error:

 Failed to execute 'contains' on 'Node': parameter 1 is not of type 'Node'.
    at HTMLFieldSetElement.<anonymous> (app.js:83)

Code:

$(activities).change(e => {
  //To get dollar sign
  let activityString = $(e.target)
    .parent()
    .text();
  const indexOfDollarSign = activityString.indexOf("$");
  let price = parseFloat(activityString.slice(indexOfDollarSign + 1));
  //To get Date and time of event
  const indexOfDash = activityString.indexOf("—");
  const indexOfComa = activityString.indexOf(",");
  console.log(indexOfDash, indexOfComa);
  const dateAndTime = activityString.slice(indexOfDash, indexOfComa);
  console.log(dateAndTime);

  if (e.target.checked === true) {
    startingCost = startingCost + price;
  } else if (e.target.checked === false) {
    startingCost = startingCost - price;
  }
  $("#total").text(`$${startingCost}`);

  for (let i = 1; i < activityInputs.length; i++) {
    /*
      find a way to filter out other events that share the same day and time of event user clicks

      Find which method works.

      Current code throws error:
      Failed to execute 'contains' on 'Node': parameter 1 is not of type 'Node'.
    */
    let input = activityInputs[i];
    if (input.contains(dateAndTime)) {
      console.log(true);
    }
  }
});

updated github js file: https://github.com/joeEscob1023/interactiveForm/blob/master/js/app.js