0

Comments pretty much explain the stuff you can't see. randInt does exactly what you'd expect, adDescription generates a description of an ad based on the return of randInt, and rLink generates a link based on the same.

<script type="text/javascript">
    rNumber = randInt(5); //generate a random integer from 1 to 5
    rAd = adDescription(rNumber); //description of the random ad
    rLink = adLink(rNumber); //URL of the random ad
    document.write("<a href='" + rLink + "'>");
    document.write("<img src='ad" + rNumber + ".jpg' alt='" + rAd "'/>");
    document.write("</a>");
</script>

My problem lies in my document.write calls.

When all is said and done, it should write the following to my html code

<a href="url">
    <img src="adn.jpg" alt="description"/>
</a>

Yes, this is for school, and I know exactly what I want to do, but for some reason it's not rendering, and in my head, this makes sense. What blatantly obvious mistake am I making that I just can't see?

Edit: Oh, and this script is being called in a predetermined part of pre-baked code that was given to me. The rest of my code worked properly prior to me inserting this code in the div element that I was instructed to. Additionally, I have called the scripts that contain the above functions in my document head.

Edit2: Yep, I feel dumb.

2
  • What do you mean by "not rendering", is nothing rendering at all? Commented Nov 20, 2014 at 2:46
  • Yes, it was not displaying anything at all. I've been given a solution, and as predicted, I feel really dumb after figuring out my problem :P Commented Nov 20, 2014 at 2:57

2 Answers 2

2

You're missing a plus sign when you write out the <img> tag

<script type="text/javascript">
    rNumber = randInt(5); //generate a random integer from 1 to 5
    rAd = adDescription(rNumber); //description of the random ad
    rLink = adLink(rNumber); //URL of the random ad
    document.write("<a href='" + rLink + "'>");
    //                                                     Missed + here
    document.write("<img src='ad" + rNumber + ".jpg' alt='" + rAd + "'/>");
    document.write("</a>");
</script>
Sign up to request clarification or add additional context in comments.

3 Comments

I knew it was just going to be some little stupid thing that I'm missing and can't see. That was definitely the problem! Thank you!
Having another set of eyes always helps haha Glad I could help :)
The Developer Tools in Chrome are great for finding issues. Press F12 on a page to open the tools. It takes time getting familiar with them but they'll save you tons of time.
0

You are missing a + sign after rAd in the img src tag.

Here is the correct code

<script type="text/javascript">
    rNumber = randInt(5); //generate a random integer from 1 to 5
    rAd = adDescription(rNumber); //description of the random ad
    rLink = adLink(rNumber); //URL of the random ad
    document.write("<a href='" + rLink + "'>");
    document.write("<img src='ad" + rNumber + ".jpg' alt='" + rAd + "'/>");
    document.write("</a>");
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.