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

andi's basic temp-converter #158

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
16 changes: 16 additions & 0 deletions index2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<html>
<head>
<link rel="stylesheet" href="style2.css">
</head>
<body onload = "checkWeather()">

<h2>Metrics: <span id="metType"></span></h2>
<h2>Degree: <span id="Tval"></span></h2>
<h2>Weather today is: </h2>
<h1 id="outputData"></h1>
<h2>Choice of clothes: </h2>
<h1 id="outputClothes"></h1>
<script src="rescript.js"></script>

</body>
</html>
121 changes: 121 additions & 0 deletions rescript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
console.log("hello script js");

// //inputValue, selectMetrics, getName
// //
// let inputVal = document.querySelector('#inputVal');
// let metrics = document.querySelector('#inputMetric');
// let output = document.querySelector('#output');
// // let selectedMet;

// const currentInput = inputVal.addEventListener('keypress', function (e) {
// if (e.key === 'Enter') {
// return inputVal.value
// }
// })

// function selectMetric(e) {
// let selectedMet = e.target.value;
// document.querySelector("#inTempMetric").innerHTML = `${selectedMet}`
// return selectedMet;
// }


let metrics;
let tempVal;

function getMetrics(){
metrics = prompt("Enter Metrics");
metrics = metrics.charAt(0).toUpperCase()+metrics.slice(1);
return metrics;
}

function getVal(){
tempVal = prompt("Enter Value");
// if (typeof(tempVal) === 'number'){
return tempVal;
// } else {
// alert("error")
// }
}


function checkInput() {
getMetrics();
getVal();
let outputData = document.querySelector("#outputData");
// if (typeof(tempVal) == 'number') {
if (metrics === "Celcius") {
let cVal = tempVal;
let fVal = (tempVal*(9/5) + 32).toFixed(2);
let kVal = (Number(273.15)+Number(tempVal)).toFixed(2); //cant get this to add up without Number()
let data = `${cVal} C = ${fVal} F = ${kVal} K`
return outputData.innerText = data
} else if (metrics === "Farenheit") {
let cVal = ((tempVal-32)*(5/9)).toFixed(2);
let fVal = tempVal;
let kVal = ((tempVal-32)*(5/9)+273.15).toFixed(2);
let data = `${cVal} C = ${fVal} F = ${kVal} K`
return outputData.innerText = data
} else if (metrics === "Kelvin") {
let cVal = (tempVal-273.15).toFixed(2);
let fVal = ((tempVal-273.15) * (9/5) + 32).toFixed(2);
let kVal = tempVal;
let data = `${cVal} C = ${fVal} F = ${kVal} K`
return outputData.innerText = data
}
// } else {
// return outputData.innerHTML = "input valid number please"
// }
}


function getName() {
let person = prompt("Please enter your name");
return person;
}


function checkWeather() {
checkInput();
let userName = getName();
let metricsOutput = document.querySelector("#metType");
metricsOutput.innerText = metrics;
let valOutput = document.querySelector("#Tval");
valOutput.innerText = tempVal;
let outputClothes = document.querySelector("#outputClothes");
if ((metrics === "Celcius" && tempVal < 0) || (metrics === "Farenheit" && tempVal < 32) || (metrics === "Kelvin" && tempVal < 273.15)) {
let msg = `ooh it's cold out; hi ${userName}, wear a heavy jacket and toe warmers`;
return outputClothes.innerText = msg;
} else if((metrics === "Celcius" && tempVal > 40) || (metrics === "Farenheit" && tempVal > 104) || (metrics === "Kelvin" && tempVal > 313.15)) {
let msg = `ooh it's hot out; hi ${userName}, wear nothing`;
return outputClothes.innerText = msg;
} else if((metrics === "Celcius" && tempVal > 100) || (metrics === "Farenheit" && tempVal > 212) || (metrics === "Kelvin" && tempVal > 373.15)) {
let msg = `it's literally boiling; hi ${userName}, stay home if you want to live`;
return outputClothes.innerText = msg;
} else {
let msg = `its an average day; hi ${userName}, wear shorts and shirt`;
return outputClothes.innerText = msg;
}
}






// const button = document.querySelectorAll(".btn");
// for (let i = 0; i < button.length; i++) {
// button[i].addEventListener("click", inputHappened)
// }

// // function display(text) {
// // output.innerText = text;
// // // output.innerText = `${inputTemp}`
// // }


// //to be put into button onclick fn
// function compiledInputComp(e) {
// selectMetric(e);
// inputHappened(currentInput);
// }
37 changes: 37 additions & 0 deletions style2.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.starter {
font-size:30px;
padding:10px;
display:block;
margin:40px;
border:3px solid blue;
}

#output{
background-color:pink;
}



#outputData {
font-size:30px;
padding:10px;
display:block;
margin:40px;
border:3px solid blue;
}

#outputClothes {
font-size:30px;
padding:10px;
display:block;
margin:40px;
border:3px solid blue;
}

#Tval {
color: blue;
}

#metType {
color: blue;
}