[英]javascript if else statement not working. It returns singleStory even if I click on the twoStory image. I have tried != and ---
const detailedEstimate = () => {
document.querySelector("#btnDisplayImage").onclick = () => {
let houseStoriesLabel = document.createElement("label");
houseStoriesLabel.innerHTML = "<br>" + "number of stories is " + houseStory + "<br>";
document.body.appendChild(houseStoriesLabel);
if (houseStory = singleStory) {
houseStory.setAttribute("src", "../images/singleStoryHouse.jpg");
document.body.appendChild(houseStory);
console.log('please make a choice');
}
你需要:
if (houseStory === singleStory)
不是
if (houseStory = singleStory)
單等號將singleStory
的值分配給houseStory
。 ===
是比較(或令人不悅的==
)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.