MCPcopy Create free account
hub / github.com/AyushSaini00/60minuteJavaScript / toggleUnits

Function toggleUnits

Weather-app/app.js:82–95  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

80
81// WHEN THE USER CLICKS ON THE TEMPERATURE ELEMENET
82function toggleUnits(){
83 if(weather.temperature.value === undefined){
84 //if the value is undefined then simply come out of the fuction
85 return;
86 }
87 if(weather.temperature.unit === 'celsius'){
88 let fahrenheit = Math.floor(celsiusToFahrenheit(weather.temperature.value));
89 tempElement.innerHTML = `${fahrenheit}<span>°F</span>`;
90 weather.temperature.unit = 'fahrenheit';
91 } else {
92 tempElement.innerHTML = `${weather.temperature.value}<span>°c</span>`;
93 weather.temperature.unit = 'celsius';
94 }
95}
96tempElement.addEventListener('click', toggleUnits);

Callers

nothing calls this directly

Calls 1

celsiusToFahrenheitFunction · 0.85

Tested by

no test coverage detected