javascript - My area calculator runs wrong and doesnt give me an error. Am a beginner so i have no clue what's going on -


alert("welcome area calculator!");  prompt("would calculate area of 2 dimensional or 3 dimensional object? type in either 2d or 3d") === objectdimension;  // user chooses dimension  if (objectdimension === "2d") {    // user chooses shape    prompt("what shape find area of? can choose rectangle, circle, or triangle.") === chosenshape;  } else if (objectdimension === "3d") {    // user chooses 3d object    prompt("what 3d object find area of. can choose long it's cube.") === chosenshape;  }    function calculatearearectangle(length, width) {    alert("the area of rectangle " + length * width + " units.");  }    function calculateareacube(length, width, height) {    alert("the area of cube " + length * width * height + " units.");  }    function calculateareatriangle(base, height) {    alert("the area of triangle " + base * height * .5 + " units.");  }    function calculateareacircle(radius) {    alert("the area of circle approximately " + 3.14 * radius * radius + "units, if 3.14 used pi.");  }    // 3d shape function calling  if (chosenshape === "cube") {    calculateareacube(      prompt("what length of cube?"),      prompt("what width of cube?"),      prompt("what height of cube?")    )  }  // 2d shape function calling  else if (chosenshape === "rectangle") {    calculatearearectangle(      prompt("what length of rectangle?"),      prompt("what width of rectangle?")      )  } else if (chosenshape === "circle") {    calculateareacircle(      prompt("what radius of circle?")      )  } else if (chosenshape === "triangle") {    calculateareatriangle(      prompt("what base of triangle?"),      prompt("what height of triangle?")      )  }

i don't understand why area calculator won't work. when use goes straight cube , doesn't give me error. doing wrong? complete beginner programming appreciated.

it looks might confused on how assign values variables. have

prompt("would calculate area of 2 dimensional or 3 dimensional object? type in either 2d or 3d") === objectdimension; 

but compares result of prompt(...) objectdimension hasn't been defined console tells you. want first declare variable assign example:

var objectdimension = prompt("would calculate area of 2 dimensional or 3 dimensional object? type in either 2d or 3d"); 

a more complete example of assignment , comparison:

var result;    result = prompt("enter 1 or 2");    if(result === "1"){      alert("you entered number one!")  } else if(result == "2") {      alert("you entered number 2!")  } else {      alert("y u no listen")  }

the == , === comparison while = assignment. may want read this , this more help


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -