
function randInt(n) {
    return Math.floor(Math.random() * n);
}
function unknownString() {
    var nums = new Array(1, 1, 1);
    
    var c = 0;
    var p = 0;
    var str = "";
    while (c < 3) {
        p = randInt(3);
        if (nums[p] == 0) { continue; }
        else { nums[p] = 0; }

        unknown = getUnknown(p, c);
        str += unknown;
        c++;
    }

    return str.substring(0, str.length - 1);
    
}


var metalsArray = new Array();


function getUnknown(n, c) {
    c = 2 * c + 1;
    switch (n) {
        case 0:
            s = "u"+c+",107.868,u"+(c+1)+",10.5,";
            metalsArray.push("silver");
            break;
        case 1:
            s = "u"+c+",102.905,u"+(c+1)+",12.4,";
            metalsArray.push("rhodium");
            break;
        case 2:
            s = "u"+c+",195.09,u"+(c+1)+",21.45,";
            metalsArray.push("platinum");
            break;
    }
    return s;
}

unknown_string = unknownString();

// silver: 10.5
// rhodium: 12.4
// platinum: 21.45

var attempt = 1;


function user_metals() {
    var select;
    var userMetals = new Array();
    for (i = 0; i < 2; i++) {
        select = document.getElementById('metal' + (i+ 1));
        if (select.selectedIndex == 0) { return null; }
        var user = select.options[select.selectedIndex].innerHTML;
        userMetals.push(user);        
    }
    return userMetals;
}


function check_metals() {
    var userMetals = user_metals();
    if (userMetals == null) {
        alert("Please choose your answers before submitting.");
        return false;
    }
    var correct = true;
    for (i = 0; i < 2; i++) {
        if (userMetals[i] != metalsArray[i]) {
            correct = false;
            break;
        }
    }
    if (correct) {
        message = "Correct! Good job.";
    } else if (attempt < 3) {
        message = "You are wrong, but you still have " + (3 - attempt) + " attempt"+(attempt == 2? "": "s")+" left.";
    } else {
        message = "Incorrect. The correct order was "+metalsArray.join(', ')+". That was your 3rd attempt, please refresh and try again.";
        metals.deactivate();
    }
    attempt++;
    
    metals.setFeedback(message, attempt);
    
    return false;
}

