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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.