Index

Assignment 15 CB - Simple symbols

Using the JavaScript language, have the function simpleSymbols(str) take the str parameter being passed and determine if it is an acceptable sequence by either returning the string true or false. The str parameter will be composed of + and = symbols with several letters between them (ie. ++d+===+c++==a) and for the string to be true each letter must be surrounded by a + symbol. So the string to the left would be false. The string will not be empty and will have at least one letter.

Enter a string to test.

$(document).ready(function() { function simpleSymbols(str) { var len = str.length, correct = true; str = str.split(''); for (var i = 0; i < len; i++) { if (str[i].match(/[a-z]/i) && (str[i - 1] !== '+' || str[i + 1] !== '+') ) { correct = false; } } return correct; } $('.test-string').click(function() { var string = $('.data input').val(); if (string === '') { $('.result p').html('Please enter a string in the input field.'); } else { $('.result p').html('String you entered is: <span>' + simpleSymbols(string) + '</span>'); } }); });