Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Maria Cecilia Le Brech
3,611 PointsCan you help me replace the for looping with a for each or map looping in this js?
THIS IS THE JS
//Back-End// var number = function(x) { for (var index = 1; index <= x; index += 1) { if (index % 15 === 0) { $(".pingpong").append("<li>" + "pingpong" + "</li>"); } else if (index % 3 === 0) { $(".pingpong").append("<li>" + "ping" + "</li>"); } else if (index % 5 === 0) { $(".pingpong").append("<li>" + "pong" + "</li>"); } else { $(".pingpong").append("<li>" + index + "</li>"); } } }; //Front-End// $(document).ready(function () { $("#blanks form").submit(function(event) { event.preventDefault(); var result = $("input#number").val(); number(result); $("#output").show(); }); }); Status API Training Shop Blog About
1 Answer
Maria Cecilia Le Brech
3,611 PointsTHIS IS THE INDEX
<!DOCTYPE html> <html> <head> <link href="css/bootstrap.css" rel="stylesheet" type="text/css"> <link href="css/styles.css" rel="stylesheet" type="text/css"> <script src="js/jquery-3.0.0.js"></script> <script src="js/scripts.js"></script> <title>Ping Pong</title> </head> <body> <div id="container"> <div class=".jumbotron"> <h1>Please input a number</h1> </div> <div id="blanks"> <form> <div class="form-group"> <label for="number">Number</label> <input id="number" class="form-control" type="text"> </div>
<button type="submit" class="btn btn-info btn-lg">Result</button>
</form>
</div>
<div id="output"> <div class="pingpong"></div>
</div> </body> </html>