javascript - How to make a sort array and count array button? -
i trying create code sorts products alphabetical order , count number of them class. know how create program 1 or other, when try put them both in doesn't work, i've tried change code around still can't find way work, must doing wrong. appreciated. here current code:
<!doctype html> <html> <body> <p>printer, tablet, router, computer, phone.</p> <p>click button sort products alphabetical order.</p> <button onclick="myfunction()">try it</button> <p id="demo"></p> <script> var products = ["printer", "tablet", "router", "computer","phone"]; document.getelementbyid("demo").innerhtml = products; function myfunction() { products.sort(); document.getelementbyid("demo").innerhtml = products; } </script> <button onclick="myfunction()">count number of products!</button> <p id="demo2"></p> <script> var products = ["printer", "tablet", "router", "computer","phone"]; prod1=products.count(); function myfunction() { products.length(); document.getelementbyid("demo2").innerhtml = products; } </script> </body> </html>
welcome programming! fun, except when it's not. gets fun again right after solve problem :)
the problem code is, if separate code inside 2 <script>
tags, still read browser single program. in case, notice make have 2 functions same name , 2 'products' arrays, , second 1 overwrite first one.
Comments
Post a Comment