troubleshooting Question

Uncaught SyntaxError: Missing initializer in const declaration

Avatar of Jon Imms
Jon ImmsFlag for United States of America asked on
JavaScript
5 Comments1 Solution200 ViewsLast Modified:
I am getting the following error in my JS file, "Uncaught SyntaxError: Missing initializer in const declaration" on line 13,14.

The function determines a users' state based on phone-number entered on an html form.

function getState(arecode) {

    // Ensure param is a string to prevent unpredictable parsing results
    if (typeof arecode !== 'string') {
        console.log('Must pass the arecode as a string.');
        return;
    }

  

    // Ensure we don't parse strings starting with 0 as octal values
    const thisarea = parseInt(areacode, 10); 
    const country;
    const state;

    

    // Code blocks alphabetized by state
    if (thisarea == 205 || 938 || 251 || 334) {
        state = 'AL';
        }
    else if (thisarea == 907 || 250 ) {
        state = 'AK';
        }
    else if (thisarea == 480 || 602 || 520 || 928) {
        state = 'AZ';
        }
    else if (thisarea == 501 || 479 || 870) {
        state = 'AR';
        }
    else if (thisarea == 213 || 310 || 424 || 619 || 714 || 415 || 949 || 916 || 408 || 669 || 805 || 510 || 909 || 760 || 209 || 626 || 650 || 951 || 562 || 707 || 925 || 661 || 559 || 530 || 541 || 831 || 858 || 323) {
        state = 'CA';
        }
    else if (thisarea == 720 || 719 || 970) {
        state = 'CO';
        }
    else if (thisarea == 203 || 959) {
        state = 'CT';
        }
    else if (thisarea == 302) {
        state = 'DE';
        }
    else if (thisarea == 786 || 407 || 561 || 813 || 904 || 754 || 727 || 850 || 239 || 321 || 941 || 352 || 772 || 386 || 863 || 785) {
        state = 'FL';
        }
    else if (thisarea == 678 || 770 || 404 || 912 || 762 || 229 || 423 || 478) {
        state = 'GA';
        }
    else if (thisarea == 808) {
        state = 'HI';
        }
    else if (thisarea == 208) {
        state = 'ID';
        }
    else if (thisarea == 847 || 630 || 773 || 312 || 708 || 618 || 217 || 779 || 309 || 872 || 815) {
        state = 'IL';
        }
    else if (thisarea == 463 || 219 || 765 || 574 || 930 || 260) {
        state = 'IN';
        }
    else if (thisarea == 515 || 319 || 712 || 563 || 641) {
        state = 'IA';
        }
    else if (thisarea == 913 || 785 || 316 || 620) {
        state = 'KS';
        }
    else if (thisarea == 859 || 502 || 270 || 606 || 513) {
        state = 'KY';
        }
    else if (thisarea == 504 || 318 || 337 || 985 || 225) {
        state = 'LA';
        }
    else if (thisarea == 207) {
        state = 'ME';
        }
    else if (thisarea == 410 || 240) {
        state = 'MD';
        }
    else if (thisarea == 617 || 978 || 351 || 781 || 339 || 413) {
        state = 'MA';
        }
    else if (thisarea == 248 || 734 || 616 || 313 || 586 || 517 || 989 || 269 || 810 || 231 || 906) {
        state = 'MI';
        }
    else if (thisarea == 612 || 651 || 952 || 763 || 507 || 218 || 320) {
        state = 'MN';
        }
    else if (thisarea == 601 || 662 || 228) {
        state = 'MS';
        }
    else if (thisarea == 314 || 816 || 573 || 417 || 636 || 660 || 479) {
        state = 'MO';
        }
    else if (thisarea == 406) {
        state = 'MT';
        }
    else if (thisarea == 704 || 336 || 910 || 828 || 252 || 919 || 984 || 651) {
        state = 'NC';
        }
    else if (thisarea == 701) {
        state = 'ND';
        }
    else if (thisarea == 402 || 308) {
        state = 'NE';
        }
    else if (thisarea == 702 || 775 || 541) {
        state = 'NV';
        }
    else if (thisarea == 603) {
        state = 'NH';
        }
    else if (thisarea == 732 || 201 || 551 || 908 || 609 || 862 || 973 || 856 || 203 || 606) {
        state = 'NJ';
        }
    else if (thisarea == 505 || 575) {
        state = 'NM';
        }
    else if (thisarea == 718 || 212 || 917) {
        state = 'NY';
        }
    else if (thisarea == 614 || 330 || 216 || 513 || 740 || 937 || 440 || 419 || 567) {
        state = 'OH';
        }
    else if (thisarea == 918 || 405 || 580 || 304) {
        state = 'OK';
        }
    else if (thisarea == 541) {
        state = 'OR';
        }
    else if (thisarea == 610 || 717 || 267 || 814 || 724 || 412 || 570 || 240 || 878) {
        state = 'PA';
        }
    
    else if (thisarea == 401) {
        state = 'RI';
        }
    else if (thisarea == 843 || 803 || 864) {
        state = 'SC';
        }
    else if (thisarea == 605 || 701) {
        state = 'SD';
        }
    else if (thisarea == 615 || 423 || 865 || 901 || 731 || 931 || 456) {
        state = 'TN';
        }
    else if (thisarea == 469 || 281 || 817 || 512 || 210 || 430 || 530 || 956 || 915 || 254 || 806 || 361 || 979 || 409 || 830 || 940 || 936 || 432 || 319 || 325 || 575 || 214) {
        state = 'TX';
        }
    else if (thisarea == 801 || 435) {
        state = 'UT';
        }
    else if (thisarea == 802) {
        state = 'VT';
        }
    else if (thisarea == 757 || 703 || 804 || 540 || 434 || 276) {
        state = 'VA';
        }
    else if (thisarea == 202) {
        state = 'DC';
        }
    else if (thisarea == 206 || 425 || 509 || 360 || 253 || 564) {
        state = 'WA';
        }
    else if (thisarea == 304) {
        state = 'WV';
        }
    else if (thisarea == 608 || 262 || 715 || 920 || 414 || 274) {
        state = 'WI';
        }
    else if (thisarea == 307) {
        state = 'WY';
        }
    else if (thisarea == 204 || 226 || 236 || 249 || 250 || 289 || 306 || 343 || 365 || 367 || 403 || 416 || 418 || 431 || 437 || 438 || 450 || 506 || 514 || 519 || 548 || 579 || 581 || 587 || 604 || 613 || 639 || 647 || 705 || 709 || 778 || 780 || 782 || 807 || 819 || 825 || 867 || 873 || 902 || 905) {
        state = 'Canada';
    }
    else {
        state = 'none';
    }

    return state;
}
    return country;
ASKER CERTIFIED SOLUTION
NorieAnalyst Assistant
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros