Help needed for Silly story generator

I’ve been trying for three hours to complete this assessment but I think I’ve stuck somewhere. I don’t know what went wrong with the code. Could you please help?
Here’s my code:
https://codepen.io/mahmoud-fed/pen/VwKeomG

And the link to the assessment:

elslamo alikom @Dev2

first you can use replaceAll which replace all the occurance of the word in the string instead of calling replace twice as you did

and you should replace “:insertx:” but you replaces “insertx”

you should make the code for getting random string inside the function result

so be like that

function result() {
  let newStory = storyText;
let xItem = randomValueFromArray(insertX);
let yItem = randomValueFromArray(insertY);
let zItem = randomValueFromArray(insertZ);
newStory = newStory.replace(':insertx:', xItem);
    newStory = newStory.replace(':inserty:', yItem);
    newStory = newStory.replace(':insertz:', zItem);
    newStory = newStory.replace(':insertx:', xItem);

you misstype in this line

 if(customName.value != '') {
newstory.replace('Bob', customName.value) 
  }

it should be newStory and also you need to write this
newStory = newStory.replace(‘Bob’, customName.value) ;

as string in js is immutable that you can not edit it you so the calling to replace just return a new string after the replacing

also in this

if(document.getElementById("uk").checked) {
    let weight = Math.round(21.4286) + ' stone';
    let temperature =  Math.round(34.4444) + ' centigrade';
    newStory.replace('94 fahrenheit', temperature);
    newStory.replace('300 pounds', weight)

  }

you missed the newStory = and so on

when you get those kind of issue try to right click the page then look into the console it help alot to know what is going on

and you can use console.log(you can write variable name here or anything you want to print)
to debug the code by print the value of certain variable to the console to check if it print the value as it should be or not

hope that help and have a nice day :slight_smile:

1 Like

Thank you so much @ justsomeone for your help. I’ve learned a lot from you. Could you give me an example of how to use replaceAll method as you suggested? Aslo I didn’t understand the following:
“when you get those kind of issue try to right click the page then look into the console it help alot to know what is going on”
when I get the console, it’s empty. I don’t see anything.
I’m sorry if I’m asking you silly questions. I’ve just started learning JS a month ago, but I’m really interested.
Thank you once again for your hekp!

elslamo alikom @Dev2

you the most welcome
check this one for the replaceALL

do not be sorry to ask anything i am learning same as you and even the most expert one sometime miss something

check this for the console.log

let us take example by your code

if(customName.value === ‘5’) { } i changed the if statement now i found that the page does not update the value of Bob even the input is not empty now i think why that happend
maybe i think to add console.log(customName.value) inside the if statement { }
now i check the console and i find it doesnot print it then maybe i think to write any value like console.log(“i am inside the if statement”) now i find that this did not print also that mean the if is always false then i go check the if condition and i find my mistake of compare it to 5
now i know the reason and fix it

could you tell me how you write the console.log and screen shoot of what you see in the console

you very welcome and i learned from you also trust me i am not kidding your mistake make me learn to debug the code also

hope that help and have a nice day :slight_smile:

Thank you @justsomeone for your reply. That helps a lot. I know how to use console.log but I meant I can’t figure out the errors from console.log. However, I ran across the sources tab and found out that the error could be explained there.
Thank you once more for your help and support!

thanks for you for letting me know about the source tab feature
and have a nice day :slight_smile: