what is my error in my code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

what is my error in my code?

I am trying to give my else statement something to do: Write an html function that pushes a “no more prompts” message into .prompt class: <!DOCTYPE html> <head> <script src="/assets/jquery.js"></script> <style> </style> </head> <body> <div class="prompt"></div> <button>Next</button> <script> // List of prompts for the user var prompts = [ 'Type your name', 'Type an adjective', 'Type a noun' ]; // Keep track of current prompt we're on var currentPrompt = 0; // A function that will call the next prompt var nextPrompt = function() { // if there is a next prompt, if (currentPrompt < prompts.length) { } //put current prompt in all html elements with class $('.prompt').html(prompts[currentPrompt]); // move the next prompt into variable currentPrompt currentPrompt = currentPrompt + 1; } //or else if we're at the end of the array else { // put a new message into the html $('.prompts').html("that's all for now!"); // do something else // $('.prompt').html("no more prompts"); } } // run nextPrompt function when button is clicked $('button').click(function() { nextPrompt(); }); // Show the first prompt as soon as js loads nextPrompt(); </script> </body>

23rd Jul 2023, 5:29 AM
Matt Troughton
7 Answers
+ 4
The first close } parenthesis after if statement is to much. When you remove then code should work. By the way here in Sololearn Playground will be needed a full internet link to source code with jQuery min.
23rd Jul 2023, 7:09 AM
JaScript
JaScript - avatar
+ 3
Matt Troughton , Don't put your code in description tag.... write your code in code playground, save it and post the link of that code playground here....
23rd Jul 2023, 5:42 AM
Riya
Riya - avatar
3rd Aug 2023, 7:52 AM
Riya
Riya - avatar
+ 2
Matt Troughton , No problem you may write your code in sololearn code playground, save it and share the link of that code playground here...as in the above code... If you put your code in description tag...we can't able to view your whole code...
3rd Aug 2023, 9:54 AM
Riya
Riya - avatar
0
How would i add the link to the code
3rd Aug 2023, 7:48 AM
Matt Troughton
0
My code didnt come from sololearn. It came from a different website
3rd Aug 2023, 8:07 AM
Matt Troughton
0
https://code.sololearn.com/W1C7jN6dSfIb/?ref=app for example tgis code. I got a syntax error in the output. Im not sure why.
3rd Aug 2023, 8:42 PM
Matt Troughton