Javascript Code Challenge

Developer
Size
1,944 Kb
Views
8,096

How do I make an javascript code challenge?

What is a javascript code challenge? How do you make a javascript code challenge? This script and codes were developed by Thomas Weld on 09 January 2023, Monday.

Javascript Code Challenge Previews

Javascript Code Challenge - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Javascript Code Challenge</title>
</head>
<body> <h2>See Console for Results</h2>
// write a method names()
// which takes a string of
// comma-separated names
// (first and last) and then
// returns an object where each
// firstname is a key, and each
// lastname is a value
//
// i.e. names("George Washington, John Adams, Kanye West")
// .. --> {
// George: "Washington",
// John: "Adams",
// Kanye: "West"
// } <script src="js/index.js"></script>
</body>
</html>

Javascript Code Challenge - Script Codes JS Codes

// write a method names()
// which takes a string of
// comma-separated names
// (first and last) and then
// returns an object where each
// firstname is a key, and each
// lastname is a value
//
// i.e. names("George Washington, John Adams, Kanye West")
// .. --> {
// George: "Washington",
// John: "Adams",
// Kanye: "West"
// }
function names(str) { var namesObj = {}; // separate names by ', ' var names = str.split(', '); // iterate on new array names.forEach( function( name ){ // split into first and last name var fullName = name.split(' '); // split into first and last names var first = fullName[0]; var last = fullName[1]; // add as key value pairs to an object namesObj[first] = last; }); // return new object return namesObj;
}
var results = names("George Washington, John Adams, Kanye West")
console.assert(results.George === "Washington")
console.assert(results['John'] === "Adams")
console.assert(results['Kanye'] === "West")
console.log(results);
Javascript Code Challenge - Script Codes
Javascript Code Challenge - Script Codes
Home Page Home
Developer Thomas Weld
Username thomasweld
Uploaded January 09, 2023
Rating 3
Size 1,944 Kb
Views 8,096
Do you need developer help for Javascript Code Challenge?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Thomas Weld (thomasweld) Script Codes
Create amazing captions with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!