'I have 3 variables which will return true or false values and i need to compare those 3 variables i need to return values i have tried below code
but this code is working only all the three variables are true please suggest for other conditions it is not working.
i would like to know how all the below condition executes.
//this is the function//
function()
{
if({{var - customJS - page_type_lookup}} === 'product' || {{var - aev - element click text}} === 'Quick View') {
var A = document.querySelector('#pdpMain > div.product-aplus-content.clearfix > div.content-desktop > div.content-container > img').getAttribute('alt').includes('A Plus Content');// variable 1
var B = document.querySelector("#rta-badge > div.rta-assembly-content > div.rta-left-section > span").innerText.includes('Assembly required');// variable 2
var C = document.querySelector('#product-content > div.product-variations.clearfix > div.attribute.variant-dropdown > div.attribute-values-section > div.label.va-navSectionalOrientation').innerText.includes('Sectional Orientation');// variable 3
//comparison // if(A === true && B === true && C === true)
{
return 'A+ Content, RTA, Sectional configurator';
}
else if(A === true && B === true && C !== true)
{
return 'A+ Content, RTA';
}
else if(A === true && B !== true && C === true)
{
return 'A+ Content, Sectional configurator';
}
else if (A !== true && B === true && C === true)
{
return 'RTA, Sectional configurator';
}
else if(A === true && B !== true && C !== true)
{
return 'A+ content';
}
else if(A !== true && B === true && C !== true)
{
return 'RTA';
}
else if(A !== true && B !== true && C === true)
{
return 'Sectional configurator';
}
else if(A !== true && B !== true && C !== true)
{
return;
}
}
}
Solution 1:[1]
f.e.:
var arr = [];
if (A) arr.push("A+ content");
if (B) arr.push("RTA");
if (C) arr.push("Sectional configurator");
return arr.join(", ");
Ok, here is an example:
function go () {
var arr = [];
if (document.getElementById("A").checked) arr.push("A+ Content");
if (document.getElementById("B").checked) arr.push("RTA");
if (document.getElementById("C").checked) arr.push("Sectional configurator");
document.getElementById("ret").value = arr.join(", ");
}
<input type="checkbox" id="A">variable A</input><br>
<input type="checkbox" id="B">variable B</input><br>
<input type="checkbox" id="C">variable C</input><br>
<button onclick="javascript:go();">Go!</button><br>
<textarea id="ret"></textarea>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
