What is wrong with my code, thanks

In 2/9 of Async section, I rewrote the code with async but it seems not right. so what is wrong please?
the link of the lesson is https://www.codecademy.com/courses/introduction-to-javascript/lessons/async-await/exercises/async-function

the code is as followings:

// Write your code below:
async function withAsync(num){
if (num === 0){
return ‘zero’;
} else {
return ‘not zero’;
}
}
withAsync(0).then((resolveValue) => {
console.log( withConstructor(0) returned a promise which resolved to: ${resolveValue}.);

and the outcome is as followings:
node app.js /home/ccuser/workspace/async-keyword/app.js:41 }); ^ SyntaxError: Unexpected end of input at createScript (vm.js:53:10) at Object.runInThisContext (vm.js:95:10) at Module._compile (module.js:543:28) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:488:32) at tryModuleLoad (module.js:447:12) at Function.Module._load (module.js:439:3) at Module.runMain (module.js:605:10) at run (bootstrap_node.js:427:7) at startup (bootstrap_node.js:151:9)

When you are calling withAsync it looks like you forgot to close the body of the call-back function with a closing curly-brace ’ } '. Make sure to first close the console.log with parenthesis ’ ) ', then close the call-back function body with the curly-brace ’ } '. And finally, close the .then method with a closing parenthesis ’ ) '. When you click on the closing parenthesis/curly-brace it should high-light the opening one as well (this works in the online-platform). Also, when you enter code in this forum you can press the </> button and paste it in for better readability.

2 Likes

</> async function withAsync(num){
if (num === 0){
return ‘zero’;
} else {
return ‘not zero’;
}
}
withAsync(0).then((resolveValue) => {
console.log( withConstructor(0) returned a promise which resolved to: ${resolveValue}. );</>

Thank you for you reply.
I added the / button, but it seems the same. could you please show me a paragraph? thanks

The use of the </> button is to press one of the icons in the forum-editor. It is only so that this editor we are discussing in now knows that we are typing in a section of code and the editor will use correct formatting. So it is not part of the JS code. Don’t type it in literally but instead look for the icon that looks like </>. Then you will get 3 backticks (`) in the editor, followed by the text “type or paste code here”, followed by 3 backticks. Replace the “type or paste code here” with the JS code. Then it is easier to read.

console.log('This is using the preformatted text mode of forum editor');
2 Likes
async function withAsync(num){
if (num === 0){
return ‘zero’;
} else {
return ‘not zero’;
}
}
withAsync(0).then((resolveValue) => {
console.log( withConstructor(0) returned a promise which resolved to: ${resolveValue}. );

Thank you so much for your reply.

Is it working now? It still looks like you are missing one curly-bracket } on the end to close the call-back function body. And then an ending parenthesis sign ) to close the .then method. Keep in mind that every opening curly-bracket and parenthesis need to have a corresponding closing one. They also need to be in the correct order. Syntax highlighting and indentation can help keep track of this but I still keep a common mistake.

I fixed the problem according to your advice.
The last reply is just to practise the </> code to better the readability.
Thank you very much.

1 Like