It is working fine on iPhone, iMac, Windows, but when I run it on an Android device, the following error is displayed in the console.
Uncaught syntaxerror unexpected token, pointing "window.onload = () =>{" this line of code.
/*
* Simple DOM test that collects the value from a textbox,
* and applies it to the header element by changing its color.
*/
window.onload= () =>{
const myheading = document.getElementById('header');
const myButton = document.getElementById('myButton');
const bgColor = document.getElementById('bgColor');
const textColor = document.getElementById('textColor');
myButton.addEventListener('click', () => {
myheading.style.color = 'black';
bgColor.style.color = bgColor.value;
textColor.style.color = textColor.value;
if (bgColor.value === '' || textColor.value === '') {
alert('Please enter color value');
myButton.style.backgroundColor= "#f00";
myButton.style.color = '#fff';
myButton.innerHTML = 'Enter Color Name';
setInterval(function() {
myButton.innerHTML = 'Change heading color';
myButton.style.backgroundColor= "#dcdcdc";
myButton.style.color = "black";
}, 5000);
} else {
myheading.innerHTML = "You changed me into <u>" + textColor.value + "</u> with a <u>" + bgColor.value + "</u> background!";
Object.assign(myheading.style, {
padding: "10px",
color: textColor.value,
backgroundColor: bgColor.value
});
myButton.style.backgroundColor= "#fd1";
myButton.innerHTML = 'Colors applied Success!';
}
});
}