Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript Is this actually JavaScript?

alvie666

New Coder
Hello, I am a newbie JS learner who was given the following quiz. I have tried working with it in a JS sandbox, but I always get errors immediately just getting started. I am also confused by the syntax itself. Is this really JS? Every time I search for info online all the returns I get are for some form of C, not JS. Any info is much appreciated!

Code:
// write code to reverse this string array in place, using a single array.

int[] arr = {3,1,5,7,6}
//
//create missing code here
//
Console.WriteLine(string.Join(",", arr))

//the end results should be the numbers in the array being returned in descending order
 
I do not think that is javascript
A basic example
JavaScript:
var arr = [3,1,5,7,6]
arr = arr.reverse() // reverse list
console.log(arr.join(', '))

output
Code:
6, 7, 5, 1, 3
 
T
Hello, I am a newbie JS learner who was given the following quiz. I have tried working with it in a JS sandbox, but I always get errors immediately just getting started. I am also confused by the syntax itself. Is this really JS? Every time I search for info online all the returns I get are for some form of C, not JS. Any info is much appreciated!

Code:
// write code to reverse this string array in place, using a single array.

int[] arr = {3,1,5,7,6}
//
//create missing code here
//
Console.WriteLine(string.Join(",", arr))

//the end results should be the numbers in the array being returned in descending order
That looks like C#, it definitely is not JavaScript. Are you sure the quiz you were given was meant to be for JavaScript?
 
Hello, I am a newbie JS learner who was given the following quiz. I have tried working with it in a JS sandbox, but I always get errors immediately just getting started. I am also confused by the syntax itself. Is this really JS? Every time I search for info online all the returns I get are for some form of C, not JS. Any info is much appreciated!

Code:
// write code to reverse this string array in place, using a single array.

int[] arr = {3,1,5,7,6}
//
//create missing code here
//
Console.WriteLine(string.Join(",", arr))

//the end results should be the numbers in the array being returned in descending order
Hi there,
A few questions:
1) Are you sure you are actually learning javascript (js) and not another language like C-Sharp (C#) or Java?
2) Are you sure the question itself isn't asking you to find the bugs in the code?

C# and javascript both use the "console" keyword to write the output, however, there are a few noticeable differences.
1) In C#, the console keyword is capitalized, whereas in javascript it's not.
2) In C#, the method used to actually write the output is "WriteLine". Notice the capitalization here. In javascript, the method to write the output is "log"
Code:
Console.WriteLine("This is how C# writes to output")
Code:
console.log("This is how javascript writes to output")
 
Hello, I am a newbie JS learner who was given the following quiz. I have tried working with it in a JS sandbox, but I always get errors immediately just getting started. I am also confused by the syntax itself. Is this really JS? Every time I search for info online all the returns I get are for some form of C, not JS. Any info is much appreciated!

Code:
// write code to reverse this string array in place, using a single array.

int[] arr = {3,1,5,7,6}
//
//create missing code here
//
Console.WriteLine(string.Join(",", arr))

//the end results should be the numbers in the array being returned in descending order
To reverse the array in place, you can use a simple loop that swaps elements from the start and end of the array, moving towards the center. Here's how you can do it:

int[] arr = {3, 1, 5, 7, 6};

for (int i = 0; i < arr.Length / 2; i++)
{
int temp = arr;
arr = arr[arr.Length - 1 - i];
arr[arr.Length - 1 - i] = temp;
}

Console.WriteLine(string.Join(",", arr));

Explanation:​

  • Loop Condition: The loop runs from 0 to arr.Length / 2, which ensures that each pair of elements (one from the start and one from the end) is swapped only once.
  • Swapping: The elements are swapped using a temporary variable temp.
  • Output: After the loop, the array arr will be reversed, and the output will show the array elements in descending order.

Result:​

Given the array {3, 1, 5, 7, 6}, the output after reversing will be:
6,7,5,1,3



The code you provided is written in C# (C-Sharp), which is a programming language developed by Microsoft. C# is widely used for developing desktop applications, web applications, games, and more, often in conjunction with the .NET framework. The syntax and structure, such as Console.WriteLine, int[], and the use of braces {}, are typical of C#.

If you want to write this code using JavaScript the code is given below :

let arr = [3, 1, 5, 7, 6];

// Reverse the array in place
arr.reverse();

// Sort the array in descending order
arr.sort((a, b) => b - a);

console.log(arr.join(","));


This code will reverse the array and then sort it in descending order. The final output when printed will be the array elements in descending order.


Hope this gonna help you better to understand.
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom