I am new to javascripting and struggling with it. I also struggle with reference sites for js because it seems I need to know the terms first to know what to search for to find what I’m looking for so I struggle really hard to find the answer on my own.
My question is simple: I have 2 scripts that I’d like to make one script, how do I do that?
I’d like this script:
https://codepen.io/Sickxiczix/pen/ZErYoja
var startDate = 1651190400000;
var newDate = new Date();
var timeNow = newDate.getTime();
var counter = Math.floor((timeNow - startDate) / 86400000) + 7;
if (counter >16) {
if (Math.floor(counter / 16) == Math.ceil(counter / 16))
{ counter = 16 }
else { counter -= (16 * Math.floor(counter / 16));
}
}
document.getElementById("day").innerHTML = counter
And this script:
https://codepen.io/Sickxiczix/pen/PoQweOo
$('#mytable tr th').each(function(){
var cellValue = $(this).html();
if(!isNaN(parseFloat(cellValue))) {
if(cellValue == 1 || cellValue == 6 || cellValue == 14 ) { // Set 1
$(this).css('background-color','#00c2ff');
$(this).css('font-weight','bold');
}
if(cellValue==2 || cellValue==7){ // Set 2
$(this).css('background-color','lime');
$(this).css('font-weight','bold');
}
if(cellValue==3 || cellValue==9){ // Set 3
$(this).css('background-color','#f8B6Ff');
$(this).css('font-weight','bold');
}
if(cellValue==4 || cellValue==10){
$(this).css('background-color','#B2BABB');
$(this).css('font-weight','bold');
}
if(cellValue==5 || cellValue==12){
$(this).css('background-color','yellow');
$(this).css('font-weight','bold');
}
if(cellValue==8 || cellValue==15){
$(this).css('background-color','#FF7043');
$(this).css('font-weight','bold');
}
if(cellValue==11 || cellValue==13 || cellValue==16){
$(this).css('background-color','#A1887F');
$(this).css('font-weight','bold');
}
}
});
To be one single script.
I’ve tried putting them together all different ways I could think of. They work without error if they’re separate as shown in the codepen links. Can someone please share how I would get them to work as one script in the same table cell?
Here is the table I want it to work on:
<table border="1" id="mytable"><tr><th>
<div style="font-size:1.5vw;">Today is day: </div></th>
<th><span id="day" style="padding: 10px;"><script src="day.js"><!-- I want both scripts working on this cell --></script></span>
</th>
</tr>
</table>
I have asked this question on Stackoverflow and for reasons beyond me a specific user that seems to be following me keeps deleting the question claiming I’m not asking my question clear enough.
I don’t know how else I can possibly ask ‘how do I put these 2 scripts together in to 1 script’ any clearer than this. I do not feel welcome on Stackoverflow since I can’t ask questions good enough for that one user that keeps deleting my questions. I hope my experience here is a better one. I’d like to feel welcome somewhere I can ask questions that help me learn.