4

i need some help with some javascript if anyone can please help

Comments
  • 2
    What's up?
  • 1
    var setWebsite = prompt("What is your favorite website?");
    var myFavorite = document.getElementById("favorite-website");
    myFavorite.innerHTML = setWebsite;

    this code prompts the user then is printed as text how would i refactor this code to print back as a link
  • 3
    Stackoverflow.com mate
  • 1
    @sias11913 we'll need to see more, but you can try this example if it helps you out:

    <!DOCTYPE html>
    <html>
    <body>
    <script>
    var response = prompt("what's your favorite website?");
    document.body.innerHTML = '<a href="' + response + '" >Click here to go to your favorite website</a>';
    </script>
    </body>
    </html>
  • 0
    @ScribeOfGoD tried that already
  • 1
    @sias11913 it’s for this coding challange n this part was a bonus I’m just trying to figure this all out
  • 0
    Guess no one knows
  • 2
    @sias11913 try document.createElement. Check mdn for documentation and examples.
  • 2
    @sias11913 and welcome to devRant.
  • 0
    The code works it prints back but the part I’m have trouble with is I need it to print out “find out and whatever url the user puts it redirects as a link
  • 0
    This gots me so mad
  • 1
    Have you checked that your selector works? Console.log it and see if it returns the correct element.

    I have sometime debugged code for like 45min and then realised that my selector was missin a dot or something.. :D
  • 0
    I have tried it all all I want is to take what the user types and how using http:// it returns as a link
  • 0
    It’s so small n stupid that I dont why no one knows how to do this
  • 1
    Post it to codepen (google it) and then link here
  • 0
    app.setWebsite = function setWebsite() {
    // code BELOW this line for challenge #3 & bonus -->
    var setWebsite = prompt("What is your favorite website?");
    var myFavorite = document.getElementById("favorite-website");
    myFavorite.innerHTML = setWebsite;
  • 0
    the first part of this is right i got it to print back the url put the bonus part is printing it back with it saying find out here and as a link directing it to the users favorite website
  • 1
    It's quite hard to help you if you don't give us enough information...

    Where is this challenge? Like some random website, CodeAcademy...link to it would be nice.

    Share your code. Not just a tiny bit about it. Share some information. Paste it to codepen or somewhere as a whole.

    Is there some other files aswell? I bet those 3 lines aren't the only ones doing something...

    If you want to ask something, do it properly. Or go to StackOverflow.
  • 0
    It’s a code challenge from general assembly
  • 0
    This is all I have And I have challange 3 it’s the bonus I’m having trouble with
  • 1
    Still need help? It's easy though people gave you many good ways to do it you just didn't take the time to try.
    <a id="favorite-website"></a>

    And in JS you also change the attribute href.

    Document.getElementById(...).setAttribute ('href', url);
  • 0
    @sias11913 So you need to complement the assignment to innerhtml to create a link instead of just text.

    Lookup the syntax for the <A href tag and just concat together a valid anchor element and your done.
  • 0
    @Voxera this makes no sense at all
  • 0
    i do want the anwser but i want to an explantion how to do this as well ive already asked this on stackover no one knows this apparently
  • 2
    @sias11913 You are demanding quite a lot since its a challenge you are supposed to do ;)

    Maybe you should try to read a little and do some easier tutorials then.
  • 0
    i thought it would be simple but it was to attempt to get into a coding school whats the point of this site if you cant learn
  • 3
    So you come to devRant to let someone else do your admission exercises for a $14 000 code bootcamp.

    Just don't try to get there. Save 13k and do some online courses.
  • 4
    @sias11913 what you are asking for is very easy, and people gave you many answers, told you what to look for and where, and still you don't know how to get all this together.. @okkimus is right, go save some money and start by learning how to read some docs
  • 0
    I don’t want the answer I want to understand the proper syntax
  • 2
    It is a very easy task, and if you cannot solve it by yourself, you clearly don't deserve the bonus points. You are basically cheating on this assignment by asking others for help
  • 0
    Thank you everyone for your input
Add Comment