Question

Write the function divideArray() in script.js that has a single numbers parameter containing an array of integers. The functi

<!DOCTYPE HTML>
<html lang="en">
   <title>JavaScript Array Lab</title>
   <script src="script.js"></script>
   <body>
       <p>To test your function, call divideArray()
from the JavaScript console in the browser.</p>
   </body>
</html>

Don't edit your code on the above code and do not copy from others', plz!

// Put your solution here in script.js

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#script.js

function divideArray(a){

let even_list=[];

let odd_list=[];

for(let i=0;i<a.length;i++){

if(a[i]%2==0){

even_list.push(a[i]);

}else{

odd_list.push(a[i]);

}

}

even_list.sort(function(a1, a2){return a1-a2})

odd_list.sort(function(a1, a2){return a1-a2})

console.log("Even numbers:");

if(even_list.length==0){

console.log("None");

}else{

for(let i=0;i<even_list.length;i++){

console.log(even_list[i]);

}

}

console.log("Odd numbers:");

if(odd_list.length==0){

console.log("None");

}else{

for(let i=0;i<odd_list.length;i++){

console.log(odd_list[i]);

}

}

}

var nums= [-18,100,16,20,4,42,56,72,88,90];

divideArray(nums);

1 2 3 4 5 6 function divideArray(a) { let even_list=[]; let odd_list=[]; for(let i=0;i<a.length; i++) { if(a[i]%2==0) { even_

#output:

Even numbers: -18 4 16 20 42 56 72 88 90 100 Odd numbers: None

Add a comment
Know the answer?
Add Answer to:
<!DOCTYPE HTML> <html lang="en">    <title>JavaScript Array Lab</title>    <script src="script.js"></script>    <body>        <p>To...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please help me with this code for javascript. <!DOCTYPE html> <html> <head> <title>Strings and Arrays</title> <script>...

    Please help me with this code for javascript. <!DOCTYPE html> <html> <head> <title>Strings and Arrays</title> <script> function wrangleArray() { var string1 = prompt("Enter: This class is going to fast");//Must be entered by the user var string1 = "";//Is this right? I want that string to change later by a series of prompt questions document.getElementById("div1").innerHTML = "<p>" + sentence + "</p>"; var words = sentence.split(" ");//I need to convert my string to an Array is this the way to do it?...

  • in the following java script code follow the instructions provided <!DOCTYPE html> <html> <head> <!-- JavaScript...

    in the following java script code follow the instructions provided <!DOCTYPE html> <html> <head> <!-- JavaScript 6th Edition Chapter 5 Hands-on Project 5-2 Author: Date:    Filename: index.htm --> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Hands-on Project 5-2</title> <link rel="stylesheet" href="styles.css" /> <script src="modernizr.custom.05819.js"></script> </head> <body> <header> <h1> Hands-on Project 5-2 </h1> </header> <article> <h2>Change of address form</h2> <form> <fieldset id="contactinfo"> <label for="addrinput"> Street Address </label> <input type="text" id="addrinput" name="Address" /> <label for="cityinput"> City </label> <input type="text" id="cityinput" name="City"...

  • <!DOCTYPE html> <html> <body> <script> // // Write a function that calculates the amount of money...

    <!DOCTYPE html> <html> <body> <script> // // Write a function that calculates the amount of money a person would earn over // a period of years if his or her salary is one penny the first day, two pennies // the second day, and continues to double each day. The program should ask the // user for the number of years and call the function which will return the total // money earned in dollars and cents, not pennies. Assume...

  • <!DOCTYPE html> <html> <body> <!-- replace the text below with your name!--> <!-- --> <!-- -->...

    <!DOCTYPE html> <html> <body> <!-- replace the text below with your name!--> <!-- --> <!-- --> <title> TYPE YOUR NAME HERE</title> <script> // // Write a program that asks the user to enter the amount that he or she has // budgeted for a month. Call a function that uses a loop that prompts the user // to enter each of his or her expenses for the month and keep a running total. // The loop finishes when the user...

  • <!DOCTYPE HTML> <html lang="en"> <head>    <meta charset="utf-8"> <title>Plaid Scarf Selector</title>    <link rel="stylesheet" href="a3.css" />...

    <!DOCTYPE HTML> <html lang="en"> <head>    <meta charset="utf-8"> <title>Plaid Scarf Selector</title>    <link rel="stylesheet" href="a3.css" />    <script src="a3.js"> </script> </head> <body>    <section>        <h1> Plaid Scarf Selector </h1><br>        <p>Feels close to real cashmere (but costs a lot less).        Think of this scarf as the next best thing to wearing authentic cashmere.        Its microsueded fabric really is that soft. In fact, at first touch some        mistake if for the real...

  • <!DOCTYPE html> <html> <body> <!-- replace the text below with your name!--> <!-- --> <!-- -->...

    <!DOCTYPE html> <html> <body> <!-- replace the text below with your name!--> <!-- --> <!-- --> <title> TYPE YOUR NAME HERE</title> <script> // // Write a program that prompts the user to enter a number within the range of // 1 through 10 and calls a function to display the roman numeral version of // that number. If the number is outside the range of 1 through 10, the program // should display an error message. // // The following...

  • <!DOCTYPE html> <html> <head> <!-- JavaScript 6th Edition Chapter 4 Hands-on Project 4-3 Author: Da...

    <!DOCTYPE html> <html> <head> <!-- JavaScript 6th Edition Chapter 4 Hands-on Project 4-3 Author: Date:    Filename: index.htm --> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Hands-on Project 4-3</title> <link rel="stylesheet" href="styles.css" /> <script src="modernizr.custom.05819.js"></script> </head> <body> <header> <h1> Hands-on Project 4-3 </h1> </header> <article> <div id="results"> <p id="resultsExpl"></p> <ul> <li id="item1"></li> <li id="item2"></li> <li id="item3"></li> <li id="item4"></li> <li id="item5"></li> </ul> </div> <form> <fieldset> <label for="placeBox" id="placeLabel"> Type the name of a place, then click Submit: </label> <input type="text" id="placeBox"...

  • This is my code so far: <!DOCTYPE html> <html> <head> <title>JavaScript is fun</title> <meta charset="utf-8" />...

    This is my code so far: <!DOCTYPE html> <html> <head> <title>JavaScript is fun</title> <meta charset="utf-8" /> </head> <body> <script type ="text/javascript"> //declare a variable and store text in it var x = "JavaScript is fun"; //write the variable 5 times document.write(x + x + x + x + x); //store 5 as string in variable x x = "5"; //store 3 as string in variable y var y = "3"; //write the value x + y to the document document.write("<br>");...

  • <!DOCTYPE html> <html> <head> <!-- JavaScript 6th Edition Chapter 8 Hands-on Project 8-1 Author: Date:   ...

    <!DOCTYPE html> <html> <head> <!-- JavaScript 6th Edition Chapter 8 Hands-on Project 8-1 Author: Date:    Filename: index.htm --> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width,initial-scale=1.0"> <title>Hands-on Project 8-1</title> <link rel="stylesheet" href="styles.css" /> <script src="modernizr.custom.65897.js"></script> </head> <body> <header> <h1> Hands-on Project 8-1 </h1> </header> <article> <h2>New Account Information</h2> <form> <fieldset id="deliveryinfo"> <label for="fnameinput">First Name</label> <input type="text" id="fnameinput" name="fname" /> <label for="lnameinput">Last Name</label> <input type="text" id="lnameinput" name="lname" /> <label for="addrinput">Street Address</label> <input type="text" id="addrinput" name="address" /> <label for="cityinput">City</label> <input type="text" id="cityinput" name="city"...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT