Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Problems with external Javascript file

    First, this is my first time coding anything seriously. I've only dabbled here and there, but no more. Any and all tips are appreciated.

    I have a program that's designed to calculate total enemy health. Its does this by taking user input on the level and enemy name. The enemy level input determines the base health stat. The enemy name determines the percent multiplier. This all runs on an onClick() event.

    I originally had this all in my <head> in my html code. It ended up being more code than I expected. So i made it an external javascript file. I did remove the <script></script> tags, I believe I have the file properly linked using the src attribute. I'm at my wits end. This is my second day of trying.

    So here is the javascript code.
    Code:
    // JavaScript Document
    
    var series;
    var index;
    var indexValue;
    var base;
    var distance;
    var sequence;
    var enemyLv;
    var enemyPct;
    var enemyHp;
    var vOneFive;
    var wrongAlert;
    var enemyList;
    var enemyName;
    var enemyInput;
    var enemyLevel;
    var a = enemyLEVEL();
    var b = enemyPCT();
    var totalHp = a * b;
    
    //calculates enemyHp and enemyPct 
    function calc(enemyHp, enemyPct) {
    	
    	a = enemyLEVEL();
    	b = enemyPCT();
    	totalHp = a * b;
    	
    	if(a && b !== -1){
    		document.getElementById('enemyTotalHp').innerHTML = totalHp;
    }
    	else{
    		alert(wrong);
    	}
    }
    
    //determines base stat for enemyHp
    function enemyLEVEL(enemyHp){
    	enemyLv = document.getElementById('enemyLevel').value;
    	var enemyLvValue = enemyLv * 1;
    	wrongAlert = "BURGA!";
    	
    	//determines which HP sequence to run
    	if(enemyLvValue <= 5){
    	
    		enemyLv = document.getElementById('enemyLevel').value;
    		enemyLvValue = enemyLv * 1;
    		series = '12345';
    		index = series.indexOf(enemyLvValue);
    		indexValue = index * 1;
    		base = 70;
    		distance = 13;
    		sequence = base + (indexValue * distance);
    		enemyHp = sequence;
    		return enemyHp;
    	}
    	
    	else if(enemyLvValue <= 10){
    		enemyLv = document.getElementById('enemyLevel').value;
    		enemyLvValue = enemyLv * 1;
    		series = '5678910';
    		index = series.indexOf(enemyLvValue);
    		indexValue = index * 1;
    		base = 122;
    		distance = 24.8;
    		sequence = base + (indexValue) * distance;
    		enemyHp = sequence;
    		return enemyHp;
    	}
    	
    	else if(enemyLvValue <= 15){
    		enemyLv = document.getElementById('enemyLevel').value;
    		enemyLvValue = enemyLv * 1;
    		series = '101112131415';
    		index = series.indexOf(enemyLvValue);
    		indexValue = index * 1;
    		base = 246;
    		distance = 50;
    		sequence = base + ((indexValue)/2) * distance;
    		enemyHp = sequence;
    		return enemyHp;
    	}
    	
    	else if(enemyLvValue <= 20){
    		enemyLv = document.getElementById('enemyLevel').value;
    		enemyLvValue = enemyLv * 1;
    		series = '151617181920';
    		index = series.indexOf(enemyLvValue);
    		indexValue = index * 1;
    		base = 496;
    		distance = 129.8;
    		sequence = base + ((indexValue)/2) * distance;
    		enemyHp = sequence;
    		return enemyHp;
    	}
    	
    	else if(enemyLvValue <= 45){
    		enemyLv = document.getElementById('enemyLevel').value;
    		enemyLvValue = enemyLv * 1;
    		series = '2021222324252627282930313233343536373839404142434445';
    		index = series.indexOf(enemyLvValue);
    		indexValue = index * 1;
    		base = 1145;
    		distance = 120;
    		sequence = base + ((indexValue)/2) * distance;	
    		enemyHp = sequence;
    		return enemyHp;
    	}
    	
    	else if(enemyLvValue <= 50){
    		enemyLv = document.getElementById('enemyLevel').value;
    		enemyLvValue = enemyLv * 1;
    		series = '454647484950';
    		index = series.indexOf(enemyLvValue);
    		indexValue = index * 1;
    		base = 4145;
    		distance = 133;
    		sequence = base + ((indexValue)/2) * distance;	
    		enemyHp = sequence;
    		return enemyHp;
    	}
    	
    	else if (enemyLvValue <= 75){
    		enemyLv = document.getElementById('enemyLevel').value;
    		enemyLvValue = enemyLv * 1;
    		series = '5051525354555657585960616263646566676869707172737475';
    		index = series.lastIndexOf(enemyLvValue);
    		indexValue = index * 1;
    		base = 4810;
    		distance = 75;
    		sequence = base + ((indexValue)/2) * distance; 
    		enemyHp = sequence;
    		return enemyHp;
    	}
    	
    	else if (enemyLvValue <= 99){
    		enemyLv = document.getElementById('enemyLevel').value;
    		enemyLvValue = enemyLv * 1;
    		series = '75767778798081828384858687888990919293949596979899';
    		index = series.lastIndexOf(enemyLvValue);
    		indexValue = index * 1;
    		base = 6685;
    		distance = 70;
    		sequence = base + ((indexValue)/2) * distance;
    		enemyHp = sequence;
    		return enemyHp;
    	}
    	
    	else if(enemyLvValue <= 110){
    		enemyLv = document.getElementById('enemyLevel').value;
    		enemyLvValue = enemyLv * 1;
    		series ='100101102103104105106107108109110';
    		index = series.indexOf(enemyLvValue);
    		indexValue = index * 1;
    		base = 8435;
    		distance = 70;
    		sequence = base + ((indexValue)/3) * distance;
    		enemyHp = sequence;
    		return enemyHp;
    	}
    	
    		else if(enemyLvValue <= 170){
    		enemyLv = document.getElementById('enemyLevel').value;
    		enemyLvValue = enemyLv * 1;
    		series ='110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170';
    		index = series.indexOf(enemyLvValue);
    		indexValue = index * 1;
    		base = 9130;
    		distance = 70;
    		sequence = base + ((indexValue)/3) * distance;
    		enemyHp = sequence;
    		return enemyHp;
    	}
    	
    	else{
    		alert(wrongAlert);
    	}
    }
    
    //determines enemyPct variable
    function enemyPCT(enemyPct){
    	enemyInput = document.getElementById('enemyUser').value;
    	enemyName = enemyInput;
    	enemyList = new Array();
    	enemyList[1] = 	"Vahra Go Vahra Delsaban Golmoro Goshin Fulyen Curtz SEED-Guardian (Tw) Special Ops (Assault) Bysha type-Koh21 Bysha type-Otsu32 Gohma Dilla Gohma Methna GSM-05 Seeker GSM-05B Bomalta GSM-05M Tirentos YG-01K BUGGE YG01U BUGGES YG-01Z BUG Deljaban Orcdillan Sendillan";//100% hp
    	//
    	enemyList[2] = "Ageeta Sageeta Rogue Wikko Special Ops (Vobis)"; //60% hp
    	//
    	enemyList[3] = "Pannon Bel Pannon Galdeen Kudetob Nava Ludda Naval Zoona Shagreece Lapucha Polty Badia Go Bajilla"; //70% hp
    	//
    	enemyList[4] = "Armed Servant (Obme) Armed Servant (Ozuna) Distova Volfu Olgohmon Bul Buna";//90% hp
    	//
    	enemyList[5] = "Koltova Kakwane Ollaka Rappy Polec AMF Heavy Infantry Armed Servant (Basta) SEED-Guardian (Kn) Delp Slami";//130%hp
    	//
    	enemyList[6] = "Booma Go Booma Jigo Booma Jishagara Vanda Vanda Merha Vanda Orga Rogue (Ogg) SEED-Guardian (Sa)";//150%hp
    	//
    	enemyList[7] = "Rogue (Jasse) Rogue Mazz Special Ops (Kanohne) Special Ops (Solda)";//180%hp
    	//
    	enemyList[8] = "Komazli Bead Groode Dilla Griena Grinna Bete C";//200%hp
    	//
    	enemyList[9] = "Bal Soza Gaozoran";//230%hp;
    	//
    	enemyList[10] = "Shinowa Hidoki" ;//250% hp
    	//
    	enemyList[11] = "Jaggo Jaggo Acte Jaggo Amure Jaggo Sonichi Zamvapas Galvapas Do Vol No Vol";//260% hp
    	//
    	enemyList[12] = "Mizura Gainozeros Grass Assassin Ubakrada Rappy Rappy Amure Rappy Latan Rappy Noel Rappy Paska";//300% hp
    	//
    	enemyList[13] = "Kamatoze Bafal Bragga";//320% hp
    	//
    	enemyList[14] = "Jarba Polavohra Hiru Vol Delnadian SEED-Ardite Zasharogan Lutus Jigga Orgdus Svaltus";//350% hp
    	//
    	enemyList[15] = "Tengohg Bil De Melan Bil De Vear Drua Gohra Kog Nadd Dilnazen Jusnagun SEED-Argine SEED-Vance SEED-Vitace Ryugtass";//400% hp
    	//
    	enemyList[16] = "Carriguine SEED-Venas";//450% hp
    	//
    	enemyList[17] = "Rappy Gugg Renvolt Magashi Grinna Bete S";//500% hp
    	//
    	enemyList[18] = "Rappy Igg";//550% hp
    	//
    	enemyList[19] = "Darbelan Alfort Tylor";//600% hp
    	//
    	enemyList[20] = "Kagajibari";//630% hp
    	//
    	enemyList[21] = "Gol Dova";//650% hp
    	//
    	enemyList[22] = "Zoal Goug"; //700% hp
    	//
    	enemyList[23] = "De Rol Le";//1000% hp
    	//
    	enemyList[24] = "SEED-Magashi";//1100% hp
    	//
    	enemyList[25] = "Alterazgohg Onmagoug";//1350% hp
    	//
    	enemyList[26] = "Adahna Dimmagolus Dark Falz";//1450% hp
    	//
    	enemyList[27] = "De Ragan Magas Maggahna";//1500% hp
    	//
    	enemyList[28] = "Dulk Fakis Mother Brain";//1650% hp
    	//
    	enemyList[29] = "De Ragnus";//1720% hp 
    
    	var one = enemyList[1];
    	var two = enemyList[2];
    	var three = enemyList[3];
    	var four = enemyList[4];
    	var five = enemyList[5];
    	var six = enemyList[6];
    	var seven = enemyList[7];
    	var eight = enemyList[8];
    	var nine = enemyList[9];
    	var ten = enemyList[10];
    	var eleven = enemyList[11];
    	var twelve = enemyList[12];
    	var thirteen = enemyList[13];
    	var fourteen = enemyList[14];
    	var fifteen = enemyList[15];
    	var sixteen = enemyList[16];
    	var seventeen = enemyList[17];
    	var eighteen = enemyList[18];
    	var nineteen = enemyList[19];
    	var twenty = enemyList[20];
    	var twentyone = enemyList[21];
    	var twentytwo = enemyList[22];
    	var twentythree = enemyList[23];
    	var twentyfour = enemyList[24];
    	var twentyfive = enemyList[25];
    	var twentysix = enemyList[26];
    	var twentyseven = enemyList[27];
    	var twentyeight = enemyList[28];
    	var twentynine = enemyList[29];
    	//
    	var indexOne = one.indexOf(enemyName);
    	var indexTwo = two.indexOf(enemyName);
    	var indexThree = three.indexOf(enemyName);
    	var indexFour = four.indexOf(enemyName);
    	var indexFive = five.indexOf(enemyName);
    	var indexSix = six.indexOf(enemyName);
    	var indexSeven = seven.indexOf(enemyName);
    	var indexEight = eight.indexOf(enemyName);
    	var indexNine = nine.indexOf(enemyName);
    	var indexTen = ten.indexOf(enemyName);
    	var indexEleven = eleven.indexOf(enemyName);
    	var indexTwelve = twelve.indexOf(enemyName);
    	var indexThirteen = thirteen.indexOf(enemyName);
    	var indexFourteen = fourteen.indexOf(enemyName);
    	var indexFifteen = fifteen.indexOf(enemyName);
    	var indexSixteen = sixteen.indexOf(enemyName);
    	var indexSeventeen = seventeen.indexOf(enemyName);
    	var indexEighteen = eighteen.indexOf(enemyName);
    	var indexNineteen = nineteen.indexOf(enemyName);
    	var indexTwenty = twenty.indexOf(enemyName);
    	var indexTwentyOne = twentyone.indexOf(enemyName);
    	var indexTwentyTwo = twentytwo.indexOf(enemyName);
    	var indexTwentyThree = twentythree.indexOf(enemyName);
    	var indexTwentyFour = twentyfour.indexOf(enemyName);
    	var indexTwentyFive = twentyfive.indexOf(enemyName);
    	var indexTwentySix = twentysix.indexOf(enemyName);
    	var indexTwentySeven = twentyseven.indexOf(enemyName);
    	var indexTwentyEight = twentyeight.indexOf(enemyName);
    	var indexTwentyNine = twentynine.indexOf(enemyName);
    	//
    	var test = "YOU CAN DO IT LITTLE NICKY! BITE HIS ****ING HEAD OFF!";
    	//
    	if(indexOne != -1){
    		var enemyPctValue = 1;	
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	//
    	else if(indexTwo != -1){
    		var enemyPctValue = 0.6;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	//
    	else if(indexThree != -1){
    		var enemyPctValue = 0.7;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	//
    	else if(indexFour != -1){
    		var enemyPctValue = 0.9;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	//
    	else if(indexFive != -1){
    		var enemyPctValue = 1.3;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	//
    	else if(indexSix != -1){
    		var enemyPctValue = 1.5;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	else if(indexSeven != -1){
    		var enemyPctValue = 1.8;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	else if(indexEight != -1){
    		var enemyPctValue = 2;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	else if(indexNine != -1){
    		var enemyPctValue = 2.3;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	else if(indexTen != -1){
    		var enemyPctValue = 2.5;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	else if(indexEleven != -1){
    		var enemyPctValue = 2.6;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	else if(indexTwelve != -1){
    		var enemyPctValue = 3;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	else if(indexThirteen != -1){
    		var enemyPctValue = 3.2;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	else if(indexFourteen != -1){
    		var enemyPctValue = 3.5;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	else if (indexFifteen != -1){
    		var enemyPctValue = 4;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	else if(indexSixteen != -1){
    		var enemyPctValue = 4.5;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	else if(indexSeventeen != -1){
    		var enemyPctValue = 5;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	else if(indexEighteen != -1){
    		var enemyPctValue = 5.5;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	else if(indexNineteen != -1){
    		var enemyPctValue = 6;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	else if(indexTwenty != -1){
    		var enemyPctValue = 6.3;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	else if(indexTwentyOne != -1){
    		var enemyPctValue = 6.5;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	else if(indexTwentyTwo != -1){
    		var enemyPctValue = 7;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	else if(indexTwentyThree != -1){
    		var enemyPctValue = 10;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	else if(indexTwentyFour != -1){
    		var enemyPctValue = 11;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	else if(indexTwentyFive != -1){
    		var enemyPctValue = 13.5;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	else if(indexTwentySix != -1){
    		var enemyPctValue = 14.5;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	else if(indexTwentySeven != -1){
    		var enemyPctValue = 15;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	else if(indexTwentyEight != -1){
    		var enemyPctValue = 16.5;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	else if(indexTwentyNine != -1){
    		var enemyPctValue = 17.2;
    		enemyPct = enemyPctValue;
    		return enemyPct;
    	}
    	else{
    		alert(enemyName);
    	}
    }
    and this is the html code
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>PSUpedia Enemy HP Calculator</title>
    <script type="text/javascript" src="hp_calc.js">
    </script>
    </head>
    
    <body>
    <form>
    Enemy Level: <input type="text" id="enemyLevel"></br>
    Enemy Name: <input type="text" id="enemyUser"></br>
    <p>EnemyHp: <b id="enemyTotalHp"> </b></p></br>
    <input type="button" value="CLICK!" onClick="calc();">
    </form>
    </body>
    </html>
    Last edited by Matsurazuki; 09-08-2011 at 12:48 AM.

  • #2
    Regular Coder
    Join Date
    Aug 2010
    Posts
    966
    Thanks
    19
    Thanked 211 Times in 209 Posts
    What i see right off is

    var a = enemyLEVEL();
    var b = enemyPCT();
    var totalHp = a * b;


    the above must be removed
    and then placed
    in body onload

    <body onload = "var a = enemyLEVEL();var b = enemyPCT();var totalHp = a * b;">

    or in a window onload handler

    just for starters.
    Last edited by DaveyErwin; 09-08-2011 at 12:33 AM.

  • Users who have thanked DaveyErwin for this post:

    Matsurazuki (09-08-2011)

  • #3
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    That actually was not the problem. I'm a fool and was editing the text file and not the .js file, Situation resolved thank you.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •