Skip to content

completed the first challenge #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions Challenge01/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<!doctype html>
<html lang="en" class="h-100">

<head>
<title>JS Challenge 01</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<title>JS Challenge 01</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
Expand Down Expand Up @@ -54,7 +51,7 @@ <h1>Longest String in an Array</h1>
<button id="btnSubmit" type="button" class="btn btn-warning">Display Hero</button>
</div>
<div class="col-12 col-md-6 order-first order-md-2">
<img src="/img/JSChallenge.png" class="img-fluid">
<img src="/img/JSChallenge.png" class="img-fluid" alt="js Challengeimage">
</div>
<div class="col-12 order-last mt-4 mb-2">
<div id="results" class="heroName display-6">
Expand Down
31 changes: 21 additions & 10 deletions Challenge01/site01.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,33 @@ const marvelHeroes = [
"Thor",
"Wasp"
]
//driver function used for display and passing values.
function findHero() {

//implement the function findLongestString that returns the longest word.
// Driver function used for display and passing values.
function findHero() {
// Implement the function findLongestString that returns the longest word.
let lword = findLongestString(marvelHeroes);

//used for display. no need to change
// Used for display.
document.getElementById("results").innerHTML = lword;

//extra credit display all of the heroes to the page

// Extra credit: display all of the heroes to the page
document.getElementById("namelist").innerHTML = marvelHeroes.join(" | ");
}

//takes an array of strings and returns the longest one.
// Takes an array of strings and returns the longest one.
function findLongestString(namesArry) {
// Declare a variable to store the longest string
let lstring = "";

return "";
for (let index = 0; index < namesArry.length; index++) {
if (namesArry[index].length > lstring.length) {
// Update lstring with the longer string
lstring = namesArry[index];
}
}

// Return the longest string
return lstring;
}

}
// Call the driver function to find and display the longest hero
findHero();