Hi! Welcome to the JavaScript Test! Some basic stuff here.

console.log("Hello World!")
Hello World!

Yeah, that's basic. I need to try a Random number generator. This will actually be a test for part of my Night at the Museum concept, specifically the one where there's a 5% chance for any question to be doubled points.

// Makes a list, declares variables
var rng 
var number
rng = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];

// Fisher-Yates Shuffle, grabbed from https://bost.ocks.org/mike/shuffle/. Very useful.
// In the theoretical jeopardy program, this script would be run every time
// the user clicks on a question.
function shuffle(rng) {
  var m = rng.length, t, i;

  // While there remain elements to shuffle…
  while (m) {

    // Pick a remaining element…
    i = Math.floor(Math.random() * m--);
    // And swap it with the current element.
    t = rng[m];
    rng[m] = rng[i];
    rng[i] = t;
  }

  return rng;
}

shuffle(rng)

// sets number, prints values of variables to verify everything is working properly
number = rng[11]
console.log(rng)
console.log(number)

// This is the random number generator

if (number == 10) {
    console.log("The number 10 was picked, in the Jeopardy this would be daily double")
} else {
    console.log("The number 10 was not picked, this is no daily double")
    console.log(number)
}
[ 19, 3, 13, 11, 15, 5, 14, 17, 16, 4, 1, 9, 20, 18, 10, 7, 8, 12, 2, 6 ]
9
The number 10 was not picked, this is no daily double
9

A few things to talk about. First, variables must be declared in Java. This looks like

var rng
var number
rng = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];

In this case, rng and number are declared. They do not have values yet. Then, I set rng equal to a list with all numbers from 1 to 20. Then I defined a function called shuffle, with the list as the parameter using function shuffle(rng) {. Here's what it does:

var m = rng.length, t, i;

This declares variables m, t, and i, and sets variable m equal to the number of entries in the list rng

while (m)

This executes associated commands on all items in the rng

i = Math.floor(Math.random() * m--);

This sets i equal to a value. Math.floor rounds any number down. Math.random() picks a random number between 0 and 1. And m-- decreases m by 1. Then:

t = rng[m];
rng[m] = rng[i];
rng[i] = t;

This sets t equal to the mth value of rng, then sets that equal to the ith value of rng, which is then set equal to t.

That's a little unclear, so I'll state that in simpler terms. This code goes to the back entry in the list and collects its value. Then, this entry is set equal to the entry randomly selected in the while loop. Then, the entry selected in the list is set equal to the former value of the last entry. Given that m-- is used for each entry, the loop effectively then repeats this process but for the second-to-last entry in the list, then the third-to-last, etc.

return rng; takes the value of the list outside the function, allowing it to be used in later commands.

number = rng[11] sets the variable number equal to the 11th entry in rng. It really doesn't matter which entry is picked since the list is randomized anyways. Then:

if (number == 10) {
    console.log("The number 10 was picked, in the Jeopardy project the given question would be daily double")
} else {
    console.log("The number 10 was not picked, this is no daily double")
    console.log(number)
}

The if statement: Essentially checks if the value of the variable number, or the 11th entry in rng, is equal to 10. Any number from 1 to 20 can be checked since all those numbers are in the list. If this is satisfied, it prints that the question in a jeopardy project would be a daily double. The function of this code is essentially a random number generator so that there's a 5% chance that a condition be satisfied. In the real jeopardy project, another command would be associated with the if statement which would double the value of a variable serving as the base number of points if a question is answered correctly.

If the condition is not satisfied, it prints that there will be no daily double.