The basic premise of this app is like a radio that saves stations to certain channels to be recalled when clicked. I keep getting the index.html:111 Uncaught ReferenceError: saveOne is not defined at HTMLButtonElement.onclick (index.html:111) error in the console and also when I mouse over the function in my VSCode i get this error: 'saveOne' is declared but its value is never read.ts(6133)
I've looked everywhere for a while now and can't find any solution or clear explanation as to why it's not working.
Thanks!
//HTML// sorry I'm new to stack overflow ::facepalm:: I assure you the html is accurate, but I don't understand how to get it to work since im a stack overflow noob.
button onclick="" value="90.1" type="button" id="channel1" class="btn btn-secondary">One /button> button type="button" onclick="saveOne()" id="save1" class="btn btn-dark save_btns">Save1 /button>
// JS FILE //
let channel1 = document.getElementById("channel1").value
function saveOne(){
let saveChnl1 = current_station.innerHTML
channel1 = saveChnl1
// console.log(channel1) //100.3
return channel1
}
OK there are so many things wrong with your question so I'll help you out.
Firstly, your html is completely invalid as it is missing correct open and close brackets.
button onclick="" value="90.1" type="button" id="channel1" class="btn btn-secondary">One /button>
button type="button" onclick="saveOne()" id="save1" class="btn btn-dark save_btns">Save1 /button>
Should be
<button value="90.1" type="button" id="channel1" class="btn btn-secondary">One</button>
<button type="button" onclick="saveOne()" id="save1" class="btn btn-dark save_btns">Save1</button>
Secondly, if you import your script correctly, you wont get any not defined errors.
Make sure that in your html head tag, you have a script tag with a src attribute like so:
<script src="script.js"></script>
and make sure that the path is correct. For information about html pathing, see HTML File Paths
Lastly, the javascript you provided wasn't valid either, but I'll assume that it uses some kind of global reference.