Sorting Names in an Array Alphabetically : Frontend Coding Exercise

This is where you can share your code for solving the Sorting Names in an Array Alphabetically exercise :slight_smile:

The title for the page is wrong :wink:

You are fast! haha. I just fixed it :slight_smile:

1 Like

HTML:

Sort Names in an Array Alphabetically

Sort Names in an Array Alphabetically


Instructions:

Arrange names in array in alphabetical order. Display results in console

CSS:
body {
background-color: cyan;
color: deeppink;
font-family: geneva, sans-serif;
}
h1 {
text-align: center;
letter-spacing: .5px;
word-spacing: 1.2px;
text-shadow: 2px 2px 2px yellow;
}
h2 {
text-align: center;
}
p {
text-align: center;
}

JS:
// Create an array of the names
const gotCharacters = [
“Jon Snow”,
“Tyrion Lannister”,
“Daenerys Targaryen”,
“Arya Stark”,
“Sansa Stark”,
“Cersei Lannister”,
“Jaime Lannister”,
“Joffrey Baratheon”,
“Robb Stark”,
“Bran Stark”,
“Stannis Baratheon”,
“Margaery Tyrell”,
“Theon Greyjoy”,
“Ramsay Bolton”,
“Petyr Baelish”
];

// Sort the array of names alphabetically
gotCharacters.sort();

// Print the sorted array to the console
console.log(gotCharacters);

Nicely done, @cynna_416! You have earned yourself a shiny new badge :trophy:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Sort Names in an Array Alphabetically</title>
    <!--<link rel="stylesheet" href="sortArrNamesStyles.css">-->
</head>
<body>
    <h1>Sort Names in an Array Alphabetically</h1>
    <br>
    <h2><u>Instructions:</u></h2>
    <p>Arrange names in array in alphabetical order.  Display results in console</p>


    <script>
        // Create an array of the names
        const gotCharacters = [
            "Jon Snow",
            "Tyrion Lannister",
            "Daenerys Targaryen",
            "Arya Stark",
            "Sansa Stark",
            "Cersei Lannister",
            "Jaime Lannister",
            "Joffrey Baratheon",
            "Robb Stark",
            "Bran Stark",
            "Stannis Baratheon",
            "Margaery Tyrell",
            "Theon Greyjoy",
            "Ramsay Bolton",
            "Petyr Baelish"
            ];

        // Sort the array of names alphabetically
        gotCharacters.sort();

        // Print the sorted array to the console
        console.log(gotCharacters);
    </script>
</body>
</html>