58531/part1/index.html
58531/part1/index.js
function parseScores(scoresString){
var result = [];
if(scoresString != "")
result = scoresString.split(" ");
return result;
}
function buildDistributionArray(scoresArray){
var scoresResult =[]; var result = [];
var a = [], b = [], prev, x=[];
var c = ["A","B","C","D","F"];
if(scoresArray.length >0){
//used standard scoring system rules
scoresArray.forEach(function(current_value, index, initial_array) {
if(current_value>=90){
scoresResult.push("A");
}else if(current_value >= 80 && current_value <=89){
scoresResult.push("B");
}else if(current_value >= 70 && current_value <=79){
scoresResult.push("C");
}else if(current_value >= 60 && current_value <=69){
scoresResult.push("D");
}else if(current_value <= 59){
scoresResult.push("F");
}
});
scoresResult.sort();
//count the element occurences in the array
for (var i = 0; i < scoresResult.length; i++ ) {
if ( scoresResult[i] !== prev ) {
a.push(scoresResult[i]);
b.push(1);
} else {
b[b.length-1]++;
}
prev = scoresResult[i];
}
//check for the missing score range eg:if no numbers are there less than 59 then need to push F => 0 in the array
c.forEach(function(current_value, index, initial_array) {
if(!a.includes(current_value)){
a.push(current_value);
b.push(0);
}
});
//final array to assign letter as index and count as value
a.forEach(function(current_value, index, initial_array) {
x[current_value]= b[index];
});
var result = [x["A"],x["B"],x["C"],x["D"],x["F"]];
}else{
var result = [0, 0, 0, 0, 0];
}
return result;
}
function setTableContent(userInput){
var inputArray = parseScores(userInput);
var distributionArray = buildDistributionArray(inputArray);
console.log(distributionArray);
if(distributionArray[0] ==0 && distributionArray[1] == 0 && distributionArray[2] == 0 && distributionArray[3] == 0 && distributionArray[4] == 0){
var html ='
No graph to display |
';
document.getElementById("distributionTable").innerHTML=html;
}else{
var html ='
';
html +=' | | | | |
';
html +='A | B | C | D | F |
';
html +=''+distributionArray[0]+' | '+distributionArray[1]+' | '+distributionArray[2]+' | '+distributionArray[3]+' | '+distributionArray[4]+' |
';
html += '';
document.getElementById("distributionTable").innerHTML=html;
}
}
function bodyLoaded(){
//Argument passed can be chnaged for testing purpose
setTableContent("45 78 98 83 86 99 90 59 67 68 65 69 75 72");
//Argument passed empty for testing purpose
//setTableContent("");
}
58531/part2/cold.gif
58531/part2/cool.gif
58531/part2/index.html
Celsius:
Fahrenheit:
58531/part2/index.js
//convert celcius to fahrenheit ( °F = °C * 9/5 + 32 )
function ConvertCtoF(celcius){
if(isNaN(parseFloat(celcius)))
{
document.getElementById("ErrDiv").innerHTML = celcius+' is not a number.'
}else{
var F = (celcius * (9/5)) + 32;
document.getElementById("FInput").value=F;
return F;
}
}
//convert fahrenheit to celcius (°C = (°F - 32) * 5/9)
function ConvertFtoC(fahrenheit){
if(isNaN(parseFloat(fahrenheit)))
{
document.getElementById("ErrDiv").innerHTML = fahrenheit+' is not a number.'
}else{
var C = (fahrenheit...