jQuery toggleClass example

Toggle class name on click in jQuery

by SHELDON PASCIAK

HTML

<div id="banner-message">
  <button>ok</button>
</div>

CSS

/*

--- Examples
maxChar("abcccccccd") === "c"
maxChar("apple 1231111") === "1"

walk through array of characters
if list exists with char as key, add char to list
compare lengths of all lists and return largest list

Write a function that returns the number of vowels
used in a string. Vowels are the characters 'a', 'e'
'i', 'o', and 'u'.

--- Examples
vowels('Hi There!') --> 3
vowels('Why do you ask?') --> 4
vowels('Why?') --> 0
or
Write a function that accepts a string. The function should
capitalize the first letter of each word in the string then
return the capitalized string.

--- Examples
capitalize('a short sentence') --> 'A Short Sentence'
capitalize('a lazy fox') --> 'A Lazy Fox'
capitalize('look, it is working!') --> 'Look, It Is Working!'



*/

body {
  background: #20262E;
  padding: 20px;
  font-family: Helvetica;
}

#banner-message {
  background: #fff;
  border-radius: 4px;
  padding: 20px;
  font-size: 25px;
  text-align: center;
  transition: all 0.2s;
  margin: 0 auto;
  width: 300px;
}

button {
  background: #0084ff;
  border: none;
  border-radius: 5px;
  padding: 8px 14px;
  font-size: 15px;
  color: #fff;
}

#banner-message.alt {
  background: #0084ff;
  color: #fff;
  margin-top: 40px;
  width: 200px;
}

#banner-message.alt button {
  background: #fff;
  color: #000;
}

JavaScript

// find elements
var banner = $("#banner-message")
var button = $("button")

function maxChar(str) {

let uniqueKeys = [];

for (var i=0;i<256;i++){
uniqueKeys[i]=0;
}
 

for (var i=0;i<str.length;i++) {

	currentChar = Math.floor(str.charAt(i));
  

uniqueKeys[currentChar]++;
 
}
console.log(uniqueKeys);

}

// handle click and add class
button.on("click", () => {
 
  
  maxChar("112");
})