2015-10-20 87 views
-2

這個程序是應該幫助子網的人,我相信我所有的邏輯都能正常工作,但是我似乎做了一些事情來產生上面的錯誤。我無法在任何地方找到此錯誤!請幫忙!我在我的JS代碼中收到了「Unexpected Token」錯誤,但我不知道哪裏出了什麼問題。

//This program's purpose is to help assist with subnetting. 

/*This section of the code is designated to holding all the subnet information. 
All of the data is put into an object in the format of 
{subNumA:#, 
subNumB:#, 
subNumC:#, 
hostNum:#, 
BlockSize:#, 
customSubMask:"#.#.#.#"} 
*/ 

/*To find block size, we subtract (the first portion of the custom subnet mask from the left that isnt a 255) 
from 256. Example: in 255.192.168.1, we would do 256-192. This number is our block size.*/ 

var objects = [ 
{ 
    cidr:8, 
    subNumA:1, 
    subNumB:0, 
    subNumC:0, 
    hostNum:16777214, 
    blockSize:256, 
    customSubMask:"255.0.0.0" 
}, 

{ 
    cidr:9, 
    subNumA:2, 
    subNumB:0, 
    subNumC:0, 
    hostNum:8388608, 
    blockSize:128, 
    customSubMask:"255.128.0.0" 
}, 

{ 
    cidr:10, 
    subNumA:4, 
    subNumB:0, 
    subNumC:0, 
    hostNum:4194304, 
    blockSize:64, 
    customSubMask:"255.192.0.0" 
}, 

{ 
    cidr:11, 
    subNumA:8, 
    subNumB:0, 
    subNumC:0, 
    hostNum:2097152, 
    blockSize:32, 
    customSubMask:"255.224.0.0" 
}, 

{ 
    cidr:12, 
    subNumA:16, 
    subNumB:0, 
    subNumC:0, 
    hostNum:1048576, 
    blockSize:16, 
    customSubMask:"255.240.0.0" 
}, 

{ 
    cidr:13, 
    subNumA:32, 
    subNumB:0, 
    subNumC:0, 
    hostNum:524288, 
    blockSize:8, 
    customSubMask:"255.248.0.0" 
}, 

{ 
    cidr:14, 
    subNumA:64, 
    subNumB:0, 
    subNumC:0, 
    hostNum:262144, 
    blockSize:4, 
    customSubMask:"255.252.0.0" 
}, 

{ 
    cidr:15, 
    subNumA:128, 
    subNumB:0, 
    subNumC:0, 
    hostNum:131072, 
    blockSize:2, 
    customSubMask:"255.254.0.0" 
}, 

{ 
    cidr:16, 
    subNumA:256, 
    subNumB:1, 
    subNumC:0, 
    hostNum:65536, 
    blockSize:256, 
    customSubMask:"255.255.0.0" 
}, 

{ 
    cidr:17, 
    subNumA:512, 
    subNumB:2, 
    subNumC:0, 
    hostNum:32768, 
    blockSize:128, 
    customSubMask:"255.255.128.0" 
}, 

{ 
    cidr:18, 
    subNumA:1024, 
    subNumB:4, 
    subNumC:0, 
    hostNum:16384, 
    blockSize:64, 
    customSubMask:"255.255.192.0" 
}, 

{ 
    cidr:19, 
    subNumA:2048, 
    subNumB:8, 
    subNumC:0, 
    hostNum:8192, 
    blockSize:32, 
    customSubMask:"255.255.224.0" 
}, 

{ 
    cidr:20, 
    subNumA:4096, 
    subNumB:16, 
    subNumC:0, 
    hostNum:4096, 
    blockSize:16, 
    customSubMask:"255.255.240.0" 
}, 

{ 
    cidr:21, 
    subNumA:8192, 
    subNumB:32, 
    subNumC:0, 
    hostNum:2048, 
    blockSize:8, 
    customSubMask:"255.255.248.0" 
}, 

{ 
    cidr:22, 
    subNumA:16384, 
    subNumB:64, 
    subNumC:0, 
    hostNum:1024, 
    blockSize:4, 
    customSubMask:"255.255.252.0" 
}, 

{ 
    cidr:23, 
    subNumA:32768, 
    subNumB:128, 
    subNumC:0, 
    hostNum:512, 
    blockSize:2, 
    customSubMask:"255.255.254.0" 
}, 

{ 
    cidr:24, 
    subNumA:65536, 
    subNumB:256, 
    subNumC:1, 
    hostNum:256, 
    blockSize:256, 
    customSubMask:"255.255.255.0" 
}, 

{ 
    cidr:25, 
    subNumA:131072, 
    subNumB:512, 
    subNumC:2, 
    hostNum:128, 
    blockSize:128, 
    customSubMask:"255.255.255.128" 
}, 

{ 
    cidr:26, 
    subNumA:262144, 
    subNumB:1024, 
    subNumC:4, 
    hostNum:64, 
    blockSize:64, 
    customSubMask:"255.255.255.192" 
}, 

{ 
    cidr:27, 
    subNumA:524288, 
    subNumB:2048, 
    subNumC:8, 
    hostNum:32, 
    blockSize:32, 
    customSubMask:"255.255.255.224" 
}, 

{ 
    cidr:28; 
    subNumA:1048576, 
    subNumB:4096, 
    subNumC:16, 
    hostNum:16, 
    blockSize:16, 
    customSubMask:"255.255.255.240" 
}, 

{ 
    cidr:29, 
    subNumA:2097152, 
    subNumB:8192, 
    subNumC:32, 
    hostNum:8, 
    blockSize:8, 
    customSubMask:"255.255.255.248" 
}, 

{ 
    cidr:30, 
    subNumA:4194304, 
    subNumB:16384, 
    subNumC:64, 
    hostNum:4, 
    blockSize:4, 
    customSubMask:"255.255.255.252" 
}, 

{ 
    cidr:31, 
    subNumA:8388608, 
    subNumB:32768, 
    subNumC:32, 
    hostNum:2, 
    blockSize:2, 
    customSubMask:"255.255.255.254" 
}, 
]; 
var classGiven = prompt("What is the class of your given network address?").toLowerCase(); 
var addressGiven = prompt("What is your given network address?"); 
var userChoice = prompt("What is your given information? ('subnets', 'hosts', 'subnets & hosts', or just a 'network address'?) Type your answer based on what is between the quotes."); 
switch(userChoice) { 
//This section is for showing info based on number of subnets only. 
case 'subnets': 
    var subnetsNeeded = prompt("How many subnets do you need?"); 
    switch(classGiven) { 
    //This is only for class A subnets. 
     case 'a': 
      function getObjectsA(subNumA, subnetsNeeded) { 
       var obj, i, il; 
       for (i = 0, il = objects.length; i < il; i++) { 
        if (objects[i].subNumA >= subnetsNeeded) { 
         obj = objects[i]; 
         break; 
        } else { 
         console.log("Something went wrong! error280"); 
         break; 
        } 
       } 
       var objectArrayTwo = obj; 
       console.log(obj); 
      } 
      getObjectsA(subNumA, subnetsNeeded); 
      break; 
    //This is only for class B subnets. 
     case 'b': 
      function getObjectsB(subNumB, subnetsNeeded) { 
       var obj, i, il; 
       for (i = 0, il = objects.length; i < il; i++) { 
        if (objects[i].subNumB >= subnetsNeeded) { 
         obj = objects[i]; 
         break; 
        } else { 
         console.log("Something went wrong! error298"); 
         break; 
        } 
       } 
       var objectArrayTwo = obj; 
       console.log(obj); 
      } 
      getObjectsB(subNumB, subnetsNeeded); 
      break; 
    //This is only for class C subnets. 
     case 'c': 
      function getObjectsC(subNumC, subnetsNeeded) { 
       var obj, i, il; 
       for (i = 0, il = objects.length; i < il; i++) { 
        if (objects[i].subNumC >= subnetsNeeded) { 
         obj = objects[i]; 
         break; 
        } else { 
         console.log("Something went wrong! error316"); 
         break; 
        } 
       } 
       var objectArrayTwo = obj; 
       console.log(obj); 
      } 
      getObjectsC(subNumC, subnetsNeeded); 
      break; 
    //This is the default case. 
     default: 
      console.log("Something went wrong! error327"); 
      break; 
    } 
    break; 
//This section is for showing info based on number of hosts only. 
case 'hosts': 
    var hostsNeeded = prompt("How many hosts do you need?"); 
    var exactHostsNeeded = hostsNeeded + 2; 
    function getObjects(hostNum, exactHostsNeeded) { 
     var obj, i, il; 
     for (i = 0, il = objects.length; i < il; i++) { 
      if (objects[i].hostNum >= exactHostsNeeded) { 
       obj = objects[i]; 
       break; 
      } else { 
       console.log("Something went wrong! error342"); 
       break; 
      } 
     } 
     var objectArrayTwo = obj; 
     console.log(obj); 
    } 
    getObjectsC(hostNum, subNumC, exactHostsNeeded, subnetsNeeded); 
    break; 
//This section is for showing info based on number of subnets and hosts only. 
case 'subnets & hosts': 
    var subnetsNeeded = prompt("How many subnets do you need?"); 
    var hostsNeeded = prompt("How many hosts do you need?"); 
    var exactHostsNeeded = hostsNeeded + 2; 
    switch(classGiven) { 
    //This is only for class A subnets. 
     case 'a': 
      function getObjectsA(hostNum, subNumA, exactHostsNeeded, subnetsNeeded) { 
       var obj, i, il; 
       for (i = 0, il = objects.length; i < il; i++) { 
        if ((objects[i].hostNum >= exactHostsNeeded) && (objects[i].subNumA >= subnetsNeeded)) { 
         obj = objects[i]; 
         break; 
        } else { 
         console.log("Something went wrong! error366"); 
         break; 
        } 
       } 
       var objectArrayTwo = obj; 
       console.log(obj); 
      } 
      getObjectsA(hostNum, subNumA, exactHostsNeeded, subnetsNeeded); 
      break; 
    //This is only for class B subnets. 
     case 'b': 
      function getObjectsB(hostNum, subNumB, exactHostsNeeded, subnetsNeeded) { 
       var obj, i, il; 
       for (i = 0, il = objects.length; i < il; i++) { 
        if ((objects[i].hostNum >= exactHostsNeeded) && (objects[i].subNumB >= subnetsNeeded)) { 
         obj = objects[i]; 
         break; 
        } else { 
         console.log("Something went wrong! error384"); 
         break; 
        } 
       } 
       var objectArrayTwo = obj; 
       console.log(obj); 
      } 
      getObjectsB(hostNum, subNumB, exactHostsNeeded, subnetsNeeded); 
      break; 
    //This is only for class C subnets. 
     case 'c': 
      function getObjectsC(hostNum, subNumC, exactHostsNeeded, subnetsNeeded) { 
       var obj, i, il; 
       for (i = 0, il = objects.length; i < il; i++) { 
        if ((objects[i].hostNum >= exactHostsNeeded) && (objects[i].subNumC >= subnetsNeeded)) { 
         obj = objects[i]; 
         break; 
        } else { 
         console.log("Something went wrong! error402"); 
         break; 
        } 
       } 
       var objectArrayTwo = obj; 
       console.log(obj); 
      } 
      getObjectsC(hostNum, subNumC, exactHostsNeeded, subnetsNeeded); 
      break; 
    //This is the default case. 
     default: 
      console.log("Something went wrong! error413"); 
      break; 
    } 
    break; 
//This section is the default for the main switch! 
default: 
    console.log("Something went wrong! error419"); 
    break; 
} 
+2

請問您的調試器給你行號?你的IDE給你提示嗎? – zero298

+0

http://www.javascriptlint.com/online_lint.php是你的朋友 –

回答

0

有在cidr:28流浪;它應該是一個,

相關問題