0
for (int i = 5; i >= 1; i--)
{
    for (int j = 0; j < i; j++)
    {
        Console.Write("*");
    }
    Console.WriteLine();
}
Console.WriteLine("---------------------------");

That is the code I am trying to run.. but it is giving error :

Uncaught SyntaxError: Unexpected identifier.

How should I resolve it?

user3378165
  • 6,546
  • 17
  • 62
  • 101
Suraj P Patil
  • 76
  • 1
  • 8

4 Answers4

2

Javascript doesn't have a strongly typed type system.

Drop the int from the for loop, replacing it with var:

for (var i = 5; i >= 1; i--)

and, once you've also substituted Console.log for Console.WriteLine, all will be well.

1

No need to declare the vartype in the for, simply use

for (i=5;i>=1;i--){ }

Try using

console.log(); 
cMarius
  • 1,090
  • 2
  • 11
  • 27
0

Both of the other answers here neglect to include an important point. Indeed you should get rid of int, but it should be replaced with var, otherwise you are declaring global variables and populating the global scope with stuff it doesn't need. Generally bad practice.

For loops should look more like this:

for (var i=5;i>=1;i--){ }
Brennan
  • 5,632
  • 2
  • 17
  • 24
0

There is no a type declaration in JavaScript nor Console.Write or Console.WriteLine, it's not c#!

Change it to console.log and declare the variables with var:

for (var i = 5; i >= 1; i--)
     {
      for (var j = 0; j < i; j++)
          {
           Console.log("*");
          }
      Console.log();
     }
Console.log("---------------------------");
user3378165
  • 6,546
  • 17
  • 62
  • 101