[Solved] "then", "catch" and "finally" methods Success text | SoloLearn: Learn to code for FREE!

+2

[Solved] "then", "catch" and "finally" methods Success text

Show the resolved text using .then method and console.log function, and save it to the successText variable. Sample Input 1: Sample Output 1: You should go to the beach! https://code.sololearn.com/WCyJ4JOYTU3S/?ref=app

7/11/2020 1:41:53 PM

Subham

27 Answers

New Answer

+3

Can you give more description?

+3

Promise tutorial https://youtu.be/s6Nd4x_RJPw

+2

// Created by Subham const isGoodWeather = false const promise = new Promise(function(resolve, reject){ if (isGoodWeather){ resolve("You should go to the beach!"); } else { reject("Sorry wether is not good") } }); promise .then(const successText => console.log(successText)) .catch(error => console.log(error))

+2

The problem you are getting error on const successText is because, you have not initialized successText.. constants cannot be left uninitialised. EDIT :: you had your question heading as "then" "catch" and "finally" , so in my previous code implementation I used all those three. second thing, the website link you have shared might have a practice area where they have their own defined test cases. which should have exact output as the test cases. this is just the implementation of "then" https://code.sololearn.com/WeC51itpmXZM/?ref=app

+2

Subham u haven't uses the "then" promise.. It's like you are just printing the message using console.log

+2

Subham There is a syntax error in your code .then(const successText => console.log(successText)) const is not valid in that position Try this .then(successText => console.log(successText))

+1

https://code.sololearn.com/W590VkAovPZS/?ref=app

+1

the resolution Sami Khan was not the part of tutorial.... the tutorial was only basic of then catch finally https://hyperskill.org/learn/step/9989

+1

Sorry, what do you mean? I don't get it. What tutorial you are talking about?

+1

Sami Khan i have posted the link

+1

Failed. Runtime error This is a sample test from the problem statement! Test input: Correct output: You should go to the beach! Your code output: Error: /sandbox/main.js:17 successText ^ ReferenceError: successText is not defined at Object.<anonymous> (/sandbox/main.js:17:1) at Module._compile (internal/modules/cjs/loader.js:688:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10) at Module.load (internal/modules/cjs/loader.js:598:32) at tryModuleLoad (internal/modules/cjs/loader.js:537:12) at Function.Module._load (internal/modules/cjs/loader.js:529:3) at Function.Module.runMain (internal/modules/cjs/loader.js:741:12) at startup (internal/bootstrap/node.js:285:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)

+1

The link you have shared, is for logged in user's, I cannot see the code which you are practicing there.

+1

Regardless it only talks about basic then catch finally. plus your code generates the error

+1

FEEDBACK Failed. Runtime error This is a sample test from the problem statement! Test input: Correct output: You should go to the beach! Your code output: Error: /sandbox/main.js:14 .then(const successText => console.log(successText)) ^^^^^ SyntaxError: Unexpected token const at new Script (vm.js:79:7) at createScript (vm.js:251:10) at Object.runInThisContext (vm.js:303:10) at Module._compile (internal/modules/cjs/loader.js:656:28) at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10) at Module.load (internal/modules/cjs/loader.js:598:32) at tryModuleLoad (internal/modules/cjs/loader.js:537:12) at Function.Module._load (internal/modules/cjs/loader.js:529:3) at Function.Module.runMain (internal/modules/cjs/loader.js:741:12) at startup (internal/bootstrap/node.js:285:19)

+1

Subham my code gives error?? Please retry you will get output in the console

+1

I did

+1

kindly read the question I am not able to follow it at all

+1

my original code produces error FEEDBACK Failed. Runtime error This is a sample test from the problem statement! Test input: Correct output: You should go to the beach! Your code output: Error: /sandbox/main.js:8 const successText; ^^^^^^^^^^^ SyntaxError: Missing initializer in const declaration at new Script (vm.js:79:7) at createScript (vm.js:251:10) at Object.runInThisContext (vm.js:303:10) at Module._compile (internal/modules/cjs/loader.js:656:28) at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10) at Module.load (internal/modules/cjs/loader.js:598:32) at tryModuleLoad (internal/modules/cjs/loader.js:537:12) at Function.Module._load (internal/modules/cjs/loader.js:529:3) at Function.Module.runMain (internal/modules/cjs/loader.js:741:12) at startup (internal/bootstrap/node.js:285:19)

+1

Under Hints: promise is an Instance of the Promise Object/Type. You can call the .then method on the promise instance created by the default code. You can either write the result to the console and assign it to the successText constant. Or you can assign it to the variable and print the variable.

+1

FEEDBACK Failed. Runtime error This is a sample test from the problem statement! Test input: Correct output: You should go to the beach! Your code output: Error: /sandbox/main.js:12 successText ^ ReferenceError: successText is not defined at Object.<anonymous> (/sandbox/main.js:12:1) at Module._compile (internal/modules/cjs/loader.js:688:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10) at Module.load (internal/modules/cjs/loader.js:598:32) at tryModuleLoad (internal/modules/cjs/loader.js:537:12) at Function.Module._load (internal/modules/cjs/loader.js:529:3) at Function.Module.runMain (internal/modules/cjs/loader.js:741:12) at startup (internal/bootstrap/node.js:285:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)