I have a function that i want displayed into the paragraph below at the click of a button. I've been searching around for how to do this and i came across the to have text be implemented on W3Schools by using "document.getElementById().innerHTML = ..." I've tried to redo different versions of the code below to get it to show the called function however i can not figure it out. The code works great in the console and with Alerts so its definitely when im trying to put it into the html is when i come across problems. Also is there a way to do it without using J-Query or other external sources? those where the only answers last time i came across this problem on a different project.) I'm also using JSfiddle so the javascript is automatically including without linking it in the HTML.
HTML
<html>
<head> </head>
<body>
<button onclick='document.getElementById("p1").innerHTML = WOGen()'>Display</button>
<p id='p1'></p>
</body>
</html>
JavaScript
function upperB() {
var upperWO = [
'pullups',
'dips',
'plank',
'incline pushups',
'decline pushups',
'pull downs'
];
return 'today is Upper Body: ' + upperWO;
}
function Legs() {
var legWO = [
'regular squats',
'split squats',
'lunges',
'calf raises',
'glut bridges'
];
return 'today is Leg Day: ' + legWO;
}
function Abs() {
var absWO = [
'crunches',
'long arm crunches',
'scissors',
'leg ups',
'crunch kicks',
'flutter kicks',
'plank',
'hollow holds',
'star plank',
'sitting punches',
'plank rolls'
];
return 'today is Ab Day: ' + absWO;
}
function Calisthenics() {
var calith = [
'bag work',
'pushups',
'crunches',
'squats'
];
return 'Today is calisthenics Day: ' + calith;
}
function WOGen() {
var NDay = new Date();
var Day = NDay.getDay();
if (Day === 0) {
return '73k and Swim Laps';
}
if (Day === 1) {
return upperB();
}
if (Day === 2) {
return Legs();
}
if (Day === 3) {
return Abs();
}
if (Day === 4) {
return Calisthenics();
}
if (Day === 5) {
return '73k and Swim Laps';
}
if (Day === 6) {
return '73k and Swim Laps';
}
}
I'm looking to insert the WOGen() function into the paragraph. I've already tried a few different ways and can not get it.
I'm also using JSfiddle so the javascript is automatically including without linking it in the HTMLI assume you have your js in seperate file. Did you include your js file to HTML?WOGen()and other functions