0

I am trying to test some JavaScript on my local computer using the Chrome browser but Chrome will not load local resources (web page written in HTML and JavaScript) and ended up with an error message: Error Code: Result_Code_Hung. Does anyone know how to fix this loading problem? Or is there an easy workaround for this?

I tried to open the webpage with Safari, still not able to load the page.

The code is quite simple:

  <body>

     <h1> Test Loading</h1>

     <script>
 
         // calculate lcm of two natural numbers using do-while 

        function lcm (a, b){

              if (a>b) {

                 let i=1; 
                 do{
                      let lcNum= (a*i % b ===0) ? a*i: a*b ; 
                  } while (i<=a); 

                  return lcNum; 
              }

              else if (b>a){

                 let i=1; 
                 do{
                        let lcNum = (b*i % a ===0) ? b*i: a*b ; 
                  } while (i<=b); 

                  return lcNum;
              }

         }

        console.log (lcm(4,6)); 

     </script>

  </body>
  • Does this answer your question? [How can you debug JavaScript which hangs the browser?](https://stackoverflow.com/questions/7289937/how-can-you-debug-javascript-which-hangs-the-browser) – Louys Patrice Bessette Jul 31 '21 at 18:38

2 Answers2

0

Show your code. It might also happen due to some extension, network issues, cache issue. But it is hard to say without seeing your code.

aryan singh
  • 374
  • 2
  • 9
0

You have infinite loop in both do...while loops. For example in second one

do{
    let lcNum = (b*i % a ===0) ? b*i: a*b ; 
} while (i<=b); 

part. i is always equal to 1 which and b is always equal to 6, that's why while loop never breaks. I suggest entering debugger into your code

function lcm (a, b){
    debugger
    ...
}

and invoke your code from chrome dev tools console like lcm(4,6)

hmble
  • 16
  • 3