When attempting to run a script, I encountered the following error message:
Function declarations are not permitted in blocks in strict mode during targeting of the 'ES3' or 'ES5' version. The modules are automatically in strict mode.
The script I am working on is in TypeScript and it looks like this:
export default () => {
if(document.getElementById("myRange")){
//slider
var slider = document.getElementById("myRange") as HTMLInputElement;
var output = document.getElementById("demo");
var gainTimeOutput = document.getElementById("time");
var sliderEco = document.getElementById("myRange-eco") as HTMLInputElement;
var outputEco = document.getElementById('demo-eco');
var eco = document.getElementById('eco');
outputEco.innerHTML = sliderEco.value;
output.innerHTML = slider.value;
function movingSlider(){ <-- Error occurs here
output.innerHTML = slider.value;
var convertSlider = parseInt(slider.value);
var convertSliderEco = parseInt(sliderEco.value);
var gainTime = Math.round(convertSlider).toString();
var gainMoney = (Math.round(convertSlider* 2).toString();
gainTimeOutput.innerHTML = gainTime + "h";
outputEco.innerHTML = sliderEco.value;
eco.innerHTML = gainMoney + "€";
}
slider.oninput = e => {
movingSlider()
};
I am puzzled by the fact that removing the line
if(document.getElementById("myRange"))
allows the code to work properly. Can anyone explain why this error is happening and suggest how to resolve it?