Need help with functions!


So here is the code
function eval2function() {
let option = document.getElementById("choices").value;

	if (option = "min"){
		else if (option = "max") {
		else if (option = "pow") {

  function GenMin(){
	let min1 = parseFloat(document.getElementById("int1").value);
	let min2 = parseFloat(document.getElementById("int2").value);

	let minnum = Math.min(min1,min2);

	document.getElementById("result").innerHTML = "Minimum is " + minnum;


  function GenMax(){
	let max1 = parseFloat(document.getElementById("int1").value);
	let max2 = parseFloat(document.getElementById("int2").value);

	let maxnum = Math.max(max1,max2);

	document.getElementById("result").innerHTML = "Maximum is " + maxnum;

  function GenPow(){
	let base = parseFloat(document.getElementById("int1").value);
	let expo = parseFloat(document.getElementById("int2").value);

	let power = Math.pow(base, expo);
	document.getElementById("result").innerHTML = "Power is equal to" + power;


So this works by you choosing one option, adding values.. and then hitting run...
that triggers the function eval. that evaluates what option it is...
and then the function for that option kicks in.

the code for the functions is perfect my mate has the same code word to word.. it is working fine.

but mine keeps showing the math.min answer.. even tho I have the other option chosen


Where did your html code go? I wanted to help you, but i need your html code


<h2> Part 1</h2>
			  <form name = "math">
			  <table name = "mathtable">
				<select id = "choices">
					<option id = "min">Find Min</option>
					<option id = "max">Find Max</option>
					<option id = "pow">Find pow</option>
				<input type = "text" id = "int1" placeholder = "Enter the first Number"> █
				<input type = "text" id = "int2" placeholder = "Enter second Number">
				<input type = "button" name = "Run" value = "Run it!" onclick = "return eval2function()">
			<div id="result"></div>


you made a trivial error here:

if (option = "min")

a single equal sign means assign, in a if condition it would make more sense to check if option equals "min"


I tried (option == min)... but when I do that the function doesn't work. I get no answer when I click the button!



var option = document.getElementById("choices").value;

this will get the value of the value attribute of <input>, given you don't have one, it will get the text (Find Min)

give your options fields value attributes so you actually get the right value for comparison.


Oh, If you would check my 1st post.. those lines are for some reason outside the code,

but I already had let option = document.getElementById("choices").value;

 function eval2function() {
		var option = document.getElementById("choices").value;
		if (option == "min"){
		else if (option == "max") {
		else if (option == "pow") {

I can't see a syntax error or an error of any kind... chrome shows nothing.


Did you read my answer? option will contain the text of the <option>this text</option> element ("Get Min" for example), this will never equal "min"

you should give your <option> a value attribute so you get the right value from document.getElementById("choices").value for your comparison.