IT 상식

make an App in Java Scrip to "chatGPT"

주주아찌 2022. 12. 16. 03:27
728x90
How do I make an App in Java Script? This App has three categorized buttons. Each button name is "Middle", "High" and "University".
 
 

To create an app with three categorized buttons in JavaScript, you can use the following steps:

  1. Create an HTML file and add a div element where you want the buttons to be displayed.
  2. Inside the div, create three button elements, one for each category.
  3. Use the document.getElementById() method to get a reference to the div element and store it in a variable.
  4. Use the innerHTML property of the div element to add text to the buttons, such as "Middle", "High", and "University".
  5. Add an onclick event listener to each button to specify the function that should be called when the button is clicked.
  6. In each event listener function, add the code that should be executed when the button is clicked. For example, you could show a message or load some data from an API.

Here is an example of what your HTML and JavaScript code might look like:

<!-- index.html -->

<html>
  <head>
    <title>My App</title>
  </head>
  <body>
    <div id="button-container"></div>
    <script src="app.js"></script>
  </body>
</html>
// app.js

// Get a reference to the button container element
var container = document.getElementById("button-container");

// Add the buttons to the container element
container.innerHTML = "<button>Middle</button><button>High</button><button>University</button>";

// Add an event listener to the first button
document.getElementById("button-container").children[0].addEventListener("click", function() {
  // Show a message when the button is clicked
  alert("Middle button clicked!");
});

// Add an event listener to the second button
document.getElementById("button-container").children[1].addEventListener("click", function() {
  // Show a message when the button is clicked
  alert("High button clicked!");
});

// Add an event listener to the third button
document.getElementById("button-container").children[2].addEventListener("click", function() {
  // Show a message when the button is clicked
  alert("University button clicked!");
});

You can adjust this code to suit your specific needs and add more functionality to the app.

728x90