jeudi 21 février 2019

Can someone help me figure out my javascript assignment for school? [on hold]

The professor wants us to output all of the array values using JavaScript formatted in HTML. The JavaScript will randomly choose one of the three sets of link data, so you will need to wrap your output commands with if else statements in case the variable you are working with are empty.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript If Statement Exercise</title>
</head>
<body>
<script>

// She gave us this to start it off.
// The first variable would be outputted using the following line of HTML:
/* if( linkName != "" )
   {
   document.write( "<h1>" + linkName + "</h1>" );
   } */

var number = Math.ceil( Math.random() * 3 );
    if( number == 1 )
    {
        var linkName = "W3Schools";
        var linkLogo = "http://www.w3schools.com/images/w3schools.png";
        var linkURL = "http://www.w3schools.com/";
        var linkDescription = "W3Schools is a web developer information website, with tutorials and references relating to web development topics such as HTML, CSS, JavaScript and PHP.";
    }

    else if( number == 2 )
    {
        var linkName = "Code Academy";
        var linkLogo = "";
        var linkURL = "https://www.codecademy.com/";
        var linkDescription = "Codecademy is an online interactive platform that offers free coding classes in 9 different programming languages.";
    }

    else
    {
        var linkName = "";
        var linkLogo = "http://www.w3.org/2008/site/images/logo-w3c-mobile-lg";
        var linkURL = "http://www.w3.org/";
        var linkDescription = "The World Wide Web Consortium is the main international standards organization for the World Wide Web.";
    }
</script>
</body>
</html>

Aucun commentaire:

Enregistrer un commentaire