Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SEI-24 Vincent #177

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
<p>temperature converter</p>
<input class="starter" id="input" placeholder="input"/>
<h2>output:</h2>
<p class="starter" id="output"></p>
<p class="starter" id="output">Please enter the temperature</p>
<script>
document.querySelector('#input').addEventListener('change', function(event){
var currentInput = event.target.value;
var output = inputHappened(currentInput);
event.target.value = "";
display( output );
});

Expand Down
115 changes: 111 additions & 4 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,114 @@
console.log("hello script js");

// define global variables
var celsius = 0;
var fahrenheit = 0;
var kelvin = 0;
var state = "default";
var temp = 0;

/*
currentInput -> string (temperature, units)

temperature will be converted from string to int

inputHappened function reads and executes the conversion functions (line 80 to 114) and feeling function (line 62 to 77).
*/

var inputHappened = function(currentInput){
console.log( currentInput );
var output = "WOW TEMPERATURE";
return output;
};
console.log(currentInput);
if (state === "default") {
if (isNaN(currentInput)) {
var output = "Please enter a valid number";
state = "default";
return output;
} else {
state = "unit";
temp = parseInt(currentInput);
var output = "Please enter the unit (F = Fahrenheit, K = Kelvin, C = Celsius)";
return output;
}
} else if (state === "unit") {
if (currentInput === "F") {
celsius = fahrenheitToCelsius(temp);
fahrenheit = temp;
kelvin = fahrenheitToKelvin(temp);
message = feeling(celsius);
var output = "F: " + fahrenheit + " C: " + celsius + " K: " + kelvin + " " + message;
return output;
} else if (currentInput === "K") {
celsius = kelvinToCelsius(temp);
fahrenheit = kelvinToFahrenheit(temp);
kelvin = temp;
message = feeling(celsius);
var output = "F: " + fahrenheit + " C: " + celsius + " K: " + kelvin + " " + message;
return output;
} else if (currentInput === "C") {
celsius = temp;
fahrenheit = celsiusToFahrenheit(temp);
kelvin = celsiusToKelvin(temp);
message = feeling(celsius);
var output = "F: " + fahrenheit + " C: " + celsius + " K: " + kelvin + " " + message;
return output;
} else {
var output = "Please enter a valid unit from the list (F, K, C)";
state = "unit";
return output;
}
}
}

// Feeling function below
var feeling = function(celsius) {
var c = parseInt(celsius);
if (c < 0) {
var output = "ooh it's cold out";
return output;
} else if (c > 40 && c < 100) {
var output = "ooh it's hot out";
return output;
} else if (c >= 100) {
var output = "you're literally boiling";
return output;
} else {
var output = "";
return output;
}
}

// Conversion functions below
function celsiusToKelvin(temp) {
celsius = parseInt(temp);
kelvin = celsius - 273;
return kelvin;
}

function kelvinToCelsius(temp) {
kelvin = parseInt(temp);
celsius = kelvin + 273;
return celsius;
}

function fahrenheitToCelsius(temp) {
fahrenheit = parseInt(temp);
celsius = (5 / 9 * (fahrenheit - 32)).toFixed(1);
return celsius;
}

function fahrenheitToKelvin(temp) {
fahrenheit = parseInt(temp);
kelvin = (5 / 9 * (fahrenheit - 32) + 273).toFixed(1);
return kelvin;
}

function celsiusToFahrenheit(temp) {
celsius = parseInt(temp);
fahrenheit = ((9 / 5 * celsius) + 32).toFixed(1);
return fahrenheit;
}

function kelvinToFahrenheit(temp) {
kelvin = parseInt(temp);
fahrenheit = ((9 / 5 * (kelvin - 273)) + 32).toFixed(1);
return fahrenheit;
}