简体   繁体   中英

JS and HTML on a chrome extension

I'm trying to make a chrome extension and I am having trouble with the popup.js and popup.html. I'm trying to make it cycle text based on the day of the week. However, I can't get my popup.js code to work. I'm not proficient at javascript or html. I use java more but I'm doing a project for my school.

Although I currently have a button, my end goal is just for once the extension in clicked open, it displays the menu. I have no idea how to begin even coding a loop based off day of the week than also formats into html.

popup.html

 <div class="row"> <div class="column large-6 medium-6 small-12"> <h1> Lunch Menu </h1> <p> filler filler filler</p> <button onclick="main()" id="buttons">Generate</button> <div id="text"> </div> </div> </div> 

popup.js

 function main() { var today = new Date(); weekday = today.getDay(); showImages = []; myText = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', ]; text = ((document.getElementById) ? document.getElementById("text")); text.innerHTML = myText[weekday]; return text; } 

In the line:

text = ((document.getElementById) ? document.getElementById("text"));

You are using a conditional (ternary) operator but not supplying the second expression. That might be the cause of your issue. I would have just put this information in a comment but I'm new to StackOverflow and don't have enough reputation to add comments.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM