Temperature


#1

Why when I choose option 2, the function transformation executes the first block of code?

var option = prompt('Você irá 1 - celsius para fahrenheit. 2 - fahrenheit para celsius? Responda com apenas 1 ou 2')

var celsius = null
var fahrenheit = null


	if (option = '1') {
		celsius = prompt('Insira o módulo da temperatura');
	} else if (option = '2') {
		fahrenheit = prompt('Insira o módulo da temperatura');
	} else {
		console.log('opção inválida')
	}


function transformation() {
	if (option = '1') {
		fahrenheit = celsius * 9 / 5 + 32
		console.log(celsius + '°C é igual a', fahrenheit + 'F')
	} else if (option = '2') {
		celsius = 5 * fahrenheit / 9 - 160 / 9
		console.log(fahrenheit + 'F é igual a', celsius + '°C')
	} else {
		console.log('opção inválida')
	}
}

transformation()




#2

This assignment in a conditional will yield true.

Use comparison operators, equality, ==’ or identity, === depending on how strinct your type matching is.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.