Problem: Write the second largest number from input to console. You can submit numbers to input until you submit 0. When you submit 0, you need to compare all the submitted numbers and console.log the second largest (don't use array). I wrote this HTML:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Drugi najveci</title> </head> <body> <form id='form'> <input type="number" id="number"> <button id="submit">Submit</button> </form> <script src="app.js"></script> </body> </html> And added input value to a variable:
document.querySelector('#form').addEventListener('submit', function(e){ e.preventDefault(); var inputNum = document.querySelector('#number').value; }); But I don't know what to do now. How to compare the numbers from every input to get them in order and select second largest?
https://stackoverflow.com/questions/65525849/find-the-second-largest-number-from-input-in-javascript January 01, 2021 at 06:00AM
没有评论:
发表评论