What is the error here? (Beginner BTW)

This is my first time using VSC, so I am new to VSC, and this is the first time I am using it. I am using a tutorial and when I run my program (on Windows Script Host) , it gives me a error even though the code is not wrong. The error I got is:

Script: E:\code.projects\JSTUT.js
Line: 4
Char: 9
Error: Expected ‘;’
Code: 800A03EC
Source: Microsoft JScript compilation error

JSTUT.js

// Pi = 4/1 - 4/3 + 4/5 - 4/7...

function calcPI(iterations){
    let pi = 0, divisor = 1;
    for(i = 0; i <= iterations; i++){
        pi = pi + (4/divisor) - (4/
        (divisor + 2));
        divisor += 4;
    }
    fibList.shift();
    document.getElementById("output1")
    .value = pi.toFixed(10);
}

let fibLib = [];
function getFibList(howMany){
   for(i = 0; i < howMany; i++){
       fibList[i] = fib(i);
   }
   document.getElementById("output1")
   .value = fibList.join(", ");
}

function fib(whichNum){
    let num1 = 1, num2 = 0, temp, 
    i = 0;
    while(i < whichNum){
        temp = num1;
        num1 = num1 + num2;
        num2 = temp;
        i++;
    }
    return num2;
}


Video:

https://www.youtube.com/watch?v=IyDVvGmzTlo&list=PLhEpn9gptQtEjUJOCmVnUx0pB0VquVvnu&index=16&t=0s

Let me know if I should give more information.
Thanks in advance, and have a great day!

You forgot a semicolon somewhere. Btw, are you running this in the browser right?

Hello~!

I believe the error comes from your for loops. You’re using i = 0 which throws an i is undefined error, because you haven’t declared that variable yet.

You declare a variable with var, let, or const. I’d use let, here. :slight_smile:

It is still giving the same error. I looked it up online and it said it has to do with running it with Internet Explorer. I don’t understand this issue.

I have checked but I can’t find a missed semicolon error anywhere :slightly_frowning_face:

And yes I am running this in the browser.

I have checked but I can’t find a missed semicolon error anywhere :slightly_frowning_face:

And yes I am running this in the browser.

Is this your whole code?

Just ran the code, and I don’t seem to get any errors.

Could you provide html file?

Someone could maybe take the tutorial code and then his code and run git diff to see differences. Or I think git bisect

I would run it, but don’t have the time.

this seems to be line 4
character 9 is after the 0
maybe you can’t put many variable declarations on the same line

Here you go.

JSTUT.html:

<!doctype html>
<html lang="en">
   <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width = device-width,
      initial-scale = 1">
      <title>JavaScript Tutorial</title>
      <link rel="stylesheet" href="https://
      stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" 
      integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" 
      crossorigin="anonymous">
      <script src="https://stackpath.bootstrapcdn.com/bootstrap/
      4.3.1/js/bootstrap.min.js" 
      integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" 
      crossorigin="anonymous"></script>
      <link rel="stylesheet" type="text/css" 
      href="mainstyle.css">
      <script src="JSTUT.js"></script>


</head>
<body>
    <div class="container">
        <div class="jumbotron">
            <h3>MadLib Generator</h3>
            <form class="form-inline">
                <input type="text" class="form-control"
                id="i0" value="Person"/>
                <input type="text" class="form-control"
                id="i1" value="Noun"/>
                <input type="text" class="form-control"
                id="i2" value="Verb"/>
                <input type="text" class="form-control"
                id="i3" value="Verb"/>
                <input type="text" class="form-control"
                id="i4" value="Verb"/>
                <input type="text" class="form-control"
                id="i5" value="Verb"/>
                <input type="text" class="form-control"
                id="i6" value="Plural Verb"/>
                <input type="text" class="form-control"
                id="i7" value="Verb"/>
                <input type="text" class="form-control"
                id="i8" value="Adjective"/>
                <input type="text" class="form-control"
                id="i9" value="Noun"/>
                <input type="text" class="form-control"
                id="i10" value="Event"/>
                <input type="text" class="form-control"
                id="i11" value="Noun"/>
                <input type="text" class="form-control"
                id="i12" value="Body Part"/>
                <input type="text" class="form-control"
                id="i13" value="Noun"/>
            </form><br><br>
            <button type="submit" class="btn-lg" 
            onClick="alert('Hello')">Hello</button>
            <button type="submit" class="btn-lg" 
            onClick="calcPI(100000000)">Get PI</button>
            <button type="submit" class="btn-lg" 
            onClick="getFibList(20)">Get Fibs</button>
            <button type="submit" class="btn-lg" 
            onClick="madLibGenerator()">MadLib 
            Generate</button><br><br>
            <div class="input-group">
                <div class="input-group-prepend">
                    <span class="input-group-text">Output</span>
                </div>
                <textarea id="output1" rows="18" 
                class="form-control"></textarea>
            </div>

        </div>
    </div>

    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" 
    integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" 
    crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/
    libs/popper.js/1.14.7/umd/popper.min.js" 
    integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" 
    crossorigin="anonymous"></script>
</body>
</html>

Is this what you wanted me to provide?

I have tried that before, but it doesn’t make a difference unfortunately :slightly_frowning_face: .

you mean you still get the same error?
has it maybe changed the line to which it refers to or you get the same exact error if you write as below?

let pi = 0;
let divisor = 1;

It is the exact same error if I write it both ways.

Heya~!

When you say you get an error from running the code, how are you running it?

I run it on a browser. Specifically Google Chrome.

Interesting - the error you posted reads like the type of error you get from trying to run a .js file directly from the windows file explorer, so I had to double check. :slight_smile:

Unfortunately, that leaves me at a loss for the error cause again.

Good news! So I found a problem with my code, it did not fix the file but when I run the whole program the JavaScript works! However, my Fib list button is not working. I will have to check it out later.

1 Like

I figured out the problem! The error is there but the whole program works now! It was just that I accidentally typed “fibLib” instead of “fibList” on line 14! Thank you everyone for helping me! I really appreciate it! I am glad it is solved now!

Line 14 (Corrected) :

let fibList = [];
1 Like