Running a function through an if/else statment


Here is my code to give you a basic understanding of what I’m trying to do.

var location = 1
var location = function () {
if(location = 1) {
function areaOne;
else if(location = 2) {
function areaTwo;
else if(location = 3) {
function areaThree;
else {

while(location = 1) {
function areaOne() {
    var areaOne = true
    var areaOne = prompt("Input 2, 3, or over")
    while(areaOne) {
    switch (areaOne) {
        case '1':
        location = 1;
    case '2':
        location = 2;
    case '3':
        location = 3;
    case 'over':
        location = 0;
        console.log("Try again");
        location = 1;

I understand there are syntax errors and the code isn’t even finished, but what I want to know is if it’s possible to run a function if it meets the requirements of the if/else statement. I’m going to make 3 area function like the one above and I want it to run the specific one according to the response you give in the prompt. With that you can travel around as if your in an RPG.


To have a function run only when it meets the requirements of an if or and else. You just need to place it inside!

But if you want it to meet the requirements then run it outside, you will need another if somewhat like this:
>>if(A&&B){var function(chablau) {//code block-do this!} }

In this case A & B need to be returned or be set to a certain value from the if and else so that this if will run!


Can you show me an example in code?


Yeah give me a sec, I´m writing an example


Here is a dumb example, it doesn´t necessarily need to be a for, you could do an if inside another if, that would work as well :wink:

var A = false;
var B = false;

for(var i = 0;i<=5;i++)
console.log(“You a banana!”);


for(var x =0; x<=2 ;x++)
console.log(“I´m a banana!”);
console.log(“We a banana”);


So what would the syntax be to run a function instead of just a console.log?


This will enable the function to be used whenever you call it in another place, it being inside another if or inside another function!

var a =true;
var b =true;


banana = function()
  prompt("are you getting this?");





Hey dude. How are you today?


How dare me?? How dare you!!!


Thank you I think I got it now.


Hey how are you Soren the Man!!!


Soren please write back to me!!!


Sorennnnnnn pleaseeee


:rage::rage::rage::rage::rage::rage::rage: no


Hey Soren how are you today?