Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You need to replace the following highlighted code (****) with some new code tha

ID: 3884922 • Letter: Y

Question

You need to replace the following highlighted code (****) with some new code that will randomly pick a smiley face from the array named smileyArray.

} else if (request.url == '/smiley') {

    var smileyArray = cool.faces;

**** var firstSmiley = smileyArray[0];

    response.write("<!DOCTYPE html><html><head><title>Cool Smiley Faces</title></head>");

    response.write(encode(firstSmiley));

    response.write("<p><a href="/">Back</a></p>");

    response.end();

I have the module implemented through the require statement I just cant figure out how to get the random used as the number for the array index in the marked code (****).

The module used to generate random number is the following (Cant modify this part of code only the one line mentioned above):

Explanation / Answer

The method to get the random used as the number for the arrayIndex is as follows:

function(){

String arr[] = { "Akshay", "Bisht", "Sumit", "Bhakt", "Ankit", "Raikuni" };
Random rand = new Random();
int no = rand.nextInt(6);
System.out.println(arr[no]);

}

Hope this helps......

Thankyou

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote