diff --git a/example.js b/example.js new file mode 100644 index 00000000..864dbedd --- /dev/null +++ b/example.js @@ -0,0 +1,14 @@ +//Certainly! Here's a simple example of JavaScript code that will display a message in the console when a button is clicked: +// Get a reference to the button element +const button = document.querySelector('button'); + +// Add a click event listener to the button +button.addEventListener('click', () => { + // Log a message to the console + console.log('Button clicked!'); +}); + +//This code uses the querySelector method to get a reference to the button element on the page, +//and the addEventListener method to add a click event listener to the button. When the button is clicked, +//the code inside the event listener function will execute, which in this case logs a message to the console using the console. +//log method.