I have objects, that has different properties, one of them is programingLanguage. So, with the function, I want to check if the object property - programmingLanguage has a value of "Java". if it has it returns true, if it doesn't it returns no data available. Here is the code below of my function.
I am stuck in the case when in object programmingLanguage property has a string value like this "C, Java", in this case, I also want to return true, when one of them is Java, but with my function, it returns no data available.
The problem is, I do not know how to check when there is 2 string values for the property if one of them matches to "Java"
function hasExamplesInJava(books) {
if (books.programmingLanguage === "Java") {
return true;
} else if (books.programmingLanguage !== "Java") {
return "No data available";
}
}
{
title: "Algorithms",
author: ["Robert Sedgewick", "Kevin Wayne"],
programmingLanguage: "Java",
}
{
title: "Structure and Interpretation of Computer Programs",
author: ["Harold Abelson", "Gerald Jay Sussman", "Julie Sussman (Contributor)"],
programmingLanguage: "JavaScript",
}
{
title: "Operating System Concepts",
author: ["Abraham Silberschatz", "Peter B. Galvin", "Greg Gagne"],
programmingLanguage: "C, Java",
}
includes()
method. If structure ofprogrammingLanguage
string is always comma separated values, I would suggest that you split it by comma and then check that array contains Java. Right now, you can change condition like this:if (books.programmingLanguage.includes("Java"))
, but then it will be problem if, for example, word JavaScript appears because function will return true.