Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8402253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:00:34+00:00 2026-06-09T22:00:34+00:00

So here’s my script: function getRandomArrayIndex(source_array) { return Math.floor(Math.random() * source_array.length); } function getRandomArrayEntry(source_array)

  • 0

So here’s my script:

function getRandomArrayIndex(source_array) {

return Math.floor(Math.random() * source_array.length);

}

function getRandomArrayEntry(source_array) {

var random_index = getRandomArrayIndex(source_array);

return source_array[random_index];

}

function getRandomV5test() {

var v5tests = [
["This should tell me I have the following amount of minutes: "],
["This is the number of times I want to jump up and down: "],
["This is a quote."],
]; var random_v5test = getRandomArrayEntry(v5tests);

return random_v5test;

}

function displayV5test(v5test) {
    var element = document.getElementById("v5test");
    if(element !== null){
        var TEXT_ROW = 0;
        var LINK_ROW = 1;
        var v5test_text = v5test[TEXT_ROW];
        var v5test_link = v5test[LINK_ROW]; 
        if (v5test_link != null) {
            element.innerHTML = '<a href="' + v5test_link + '">' + v5test_text + '</a>';
        } else {
            element.innerHTML = v5test_text + '<span id="time"></span>';
        }
    }
}

function generateRandomV5test(){

var random_v5test = getRandomV5test();

displayV5test(random_v5test);

}

What this does is, in combination with multiple sibling scripts, generates a phrase with a random outcome. It runs before other scripts which insert their random phrase into the span id specified (‘time’), and the end result on a page might be something along the lines of:

This should tell me I have the following amount of minutes: 40

The problem is that this gives me no flexibility – the span I specify after ‘v5test_text’ must always come afterwards. In addition, the third array option would still return a random number regardless of what array option was chosen by the script, looking like this:

This is a quote. 25

What I want to be able to do is put the html code inside different array options, like the following:

var v5tests = [
["This should tell me I have <span id="time"></span> minutes. "],
["I want to jump up and down <span id="time"></span> times. "],
["This is a quote."],

So, really it’s a simple question. What syntax do I use if I want to prevent html code used in this instance being confused by the script itself? Knowing this will give me almost unlimited flexibility in terms of the content of my website.

Any help would be very much appreciated! 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:00:36+00:00Added an answer on June 9, 2026 at 10:00 pm

    Use single quotes to define your strings…

    var v5tests = [
    ['This should tell me I have <span id="time"></span> minutes.'],
    ['I want to jump up and down <span id="time"></span> times.'],
    ['This is a quote.'],
    

    Or Escape your double quotes inside the strings:

    var v5tests = [
    ["This should tell me I have <span id=\"time\"></span> minutes. "],
    ["I want to jump up and down <span id=\"time\"></span> times. "],
    ["This is a quote."],
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the Javascript I currently have <script type=text/javascript> $(function() { $('.slideshow').hover( function() {
Here is the script I'm using, copied directly from Google: <script type=text/javascript> var _gaq
Here's my code in the <head></head> : <link rel=stylesheet href=http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css /> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script>
Here is the code in a function I'm trying to revise. This example works
Here is my SQL script CREATE TABLE tracks( track_id int NOT NULL AUTO_INCREMENT, account_id
Here is an example. foreach (var doc in documents) { var processor = this.factory.Create();
Here is a simple timepicker to jQuery UI's datepicker <script type=text/javascript> /* <![CDATA[ */
Here's my test function (c#, visual studio 2010): [TestMethod()] public void TestGetRelevantWeeks() { List<sbyte>
Here is my AJAX call: $(document).ready(function () { $(#btnSignup).click(function () { $.ajax({ type: POST,
Here is a common practice in JavaScript: (function($) { ...code... })(jQuery); I understand the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.