Hi @Sneha_Swara
Well done!
A small hint to make your code a bit more robust:
Texts tend to change over time in projects, therefore you could also base your condition on the class name (and also change it accordingly). This way you can change the button text later without touching the logic (the condition).
Something like this:
const btn = document.querySelector('.off');
btn.addEventListener('click', () => {
if (btn.className === 'on') {
btn.textContent = 'Machine is off';
btn.className = "off";
} else {
btn.textContent = 'Machine is on';
btn.className = "on";
}
});
I hope that helps,
Michael