I’m very green and I’m just trying to patch together different pieces of code to pass a test (to be accepted into an Software Development Apprenticeship). I’ve found that my Javascript works less if all the functions are in the same file and even dividing them, not all of them work or work properly: one that is supposed to change the whole page to shades of grey, but works only on the wireframe instead of the whole ; one that is supposed to change the “Name” textbox to pink when clicking out (if the content is invalid) doesn’t work at all (I tried doing it on CSS as well, but it gives me pink textboxes from the start, which is not part of the requirements); one that translates some strings, does it to all except the bottom two. The only one that seems to be working fine (if the JS is in a separate file) is the captcha one. On top of that, I commented out certain things that’d make everything look weird and for what I couldn’t find a fix (for example, next to the “Providers” I wanted a radio multiple choice). Could you please help me? It’s not adamant that everything is perfect, but I don’t want to burn my chances presenting a terrible product, even though this is not what the Apprenticeship is about.
This is my HTML:
<!DOCTYPE html>
<html lang="en", "it", "es">
<head>
<title data-mlr-text>Validation Page</title>
<link rel="icon" type="image/x-icon" href="favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--I used ANSI instead of UTF-8 to incorporate all the possible variations of letters for the Name form-->
<meta charset="ANSI">
<meta name="viewport" content=
"width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="captcha.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.3/css/all.css" integrity="sha384-SZXxX4whJ79/gErwcOYf+zWLeJdY/qpuqC4cAa9rOGUstPomtqpuNWT9wdPEn2fk" crossorigin="anonymous">
<link rel="stylesheet" href="softwareDevTechnicalChallenge_TaskOne_Development.css">
<script src="captcha.js"></script>
<!--I divided the JS files and linked them separately, because I had some issue with some code and it felt better in working on them separately-->
</head>
<body onload="generate()">
<br>
<br>
<br>
<div id="wireframe">
<form>
<!--action="mailto:[email protected]" method="POST" enctype="multipart/form-data" name="EmailForm"-->
<div class="settings">
<!--Name and surname input-->
<label for="name" data-mlr-text>Name</label>
<input type="text" id="nameBox" placeholder="Write your full name here" title="Write your full name" pattern="w{1,747}" required onfocusout=validateName()>
<!--Email input; I figured an email couldn't be smaller than 5 characters, even minimized like [email protected]>
<label for="email" data-mlr-text>Email</label>
<input type="email" id:"email" name="email" placeholder="Write your email address here" title="Write your email address" maxlength="345" minlength="5" required>
<!--Card provider choice-->
<label for="provider" title="Choose your Debit/Credit Card's provider" data-mlr-text>Provider</label><br>
<!-- Commented out because it messes with the formatting and sizes
<input type="radio" id="visa" name="card_providers" value="Visa">
<label for="visa">Visa</label>
<input type="radio" id="mastercard" name="card_provider" value="Mastercard">
<label for="mastercard">Mastercard</label>
<input type="radio" id="americanexpress" name="card_provider" value="American Express">
<label for="americanexpress">American Express</label>-->
<!--Debit/Credit Card input; I set the type to password as an added layer of security-->
<label for="card" data-mlr-text>Card</label>
<input type="password" placeholder="Write your Credit/Debit Card here" title="Write your Credit/Debit Card number" pattern="d{10,19}" required>
<!--CVV/CVC input-->
<label for="cvv">CVV/CVC</label>
<input type="text" placeholder="CVV/CVC" title="Write the security number on the back of your card" pattern="d{3,4}" required><br>
<div id="user-input" class="inline">
<input type="text" id="submit" placeholder="Captcha code" required/>
</div>
<div class="inline" onclick="generate()">
<i class="fas fa-sync"></i>
</div>
<div id="image" class="inline" selectable="False">
</div>
<p id="key"></p>
</div>
<!--do the button with an Alt text and the captcha-->
<div class="button">
<input type="submit" class="button" value="Submit" type="submit" title="Click to submit your credentials!">
</div>
</div>
</form>
<br>
<br>
<br>
<br>
<br>
<div id="footer">
<hr>
<form>
<div id="footer1">
<!--To view the page with shades of grey-->
<p name="gshades" title="Click to see the page in shades of grey" onclick="shadesOfGrey()" data-mlr-text>View in Greys</p>
</div>
<div id="footer2">
<!--To view the page in another languages-->
<label for="language" title="Choose another language" data-mlr-text>Change Language</label>
<select name="language" class="mb-POCControls_Selector" id="mbPOCControlsLangDrop">
<option value="en">English</option>
<option value="it">Italiano</option>
<option value="es">Español</option>
</select>
</div>
</form>
</div>
<script src="softwareDevTechnicalChallenge_TaskOne_Development_3.js"></script>
<script src="softwareDevTechnicalChallenge_TaskOne_Development.js"></script>
<script src="softwareDevTechnicalChallenge_TaskOne_Development_2.js"></script>
<script src="softwareDevTechnicalChallenge_TaskOne_Development_4.js"></script>
</body>
</html>
This is my CSS:
body {
/*setting the green colour per request, just semi-transparent to highlight the wireframe*/
background-color: rgba(137, 200, 46, .5);
text-align: center;
font-size: 18px;
font-family: calibri;
color: rgba(60, 60, 59);
}
.button {
background-color: rgba(231, 0, 100);
border: 1px;
color: rgba(60, 60, 59);
padding: 4px 12px;
text-align: center;
text-decoration: none;
display: inline-block;
margin: 2px 1px;
cursor: pointer;
border-radius: 35px;
font-size: 18px;
font-family: calibri;
}
#wireframe {
background-color: rgba(137, 200, 46);
padding: 10px;
border-radius: 25px;
border: 4px solid #3c3c3b;
width: 400px;
margin: auto;
}
/*this is going to be the wrapper for the two footers; I'm dividing them in case I want to do different things with them*/
#footer {
position: fixed;
bottom: 0;
text-align: center;
width: 100%;
margin: auto;
overflow: auto;
}
#footer1 {
padding: 5px;
float: left;
position: sticky;
left: 500px;
}
#footer2 {
padding: 23px;
float: right;
position: sticky;
right: 400px;
}
/*As with the body bg colour, the hr is semi-transparent*/
hr {
display: block;
margin-top: 0.5em;
margin-bottom: -1%;
margin-left: auto;
margin-right: auto;
border-style: dashed;
border-width: 1px;
color: rgba(60, 60, 59, .5);
}
div.settings {
display: grid;
grid-template-columns: 96.7px 203.3px;
grid-template-rows: 33.3px 33.3px 33.3px 33.3px 33.3px;
gap: 10px 43px;
grid-template-areas:
". ."
". ."
". ."
". ."
". .";
}
div.settings label {
text-align: right;
}
div.settings label:after {
content: ":";
}
input[type=text] {
width: max;
}
#image {
margin-top: 10px;
box-shadow: 3px 3px 3px 3px gray;
width: 60px;
padding: 20px;
font-weight: 400;
padding-bottom: 0px;
height: 40px;
user-select: none;
text-decoration:line-through;
font-style: italic;
font-family: Calibri;
border: red 2px solid;
margin-left: 10px;
}
#user-input {
box-shadow: 3px 3px 3px 3px #3c3c3b;
width:auto;
margin-right: 10px;
padding: 10px;
padding-bottom: 0px;
height: 40px;
border: #700064 0px solid;
}
input {
border:1px #3c3c3b solid;
}
.inline {
display:inline-block;
}
/* Commented out as it's not working as it should: white before clicking on it, pink if clicking out when the input is invalid. It does turn green when the input is valid, though.
input:invalid {
background-color: rgba(231, 0, 100);
}
input:valid {
background-color: rgba(137, 200, 46);
} */
input:required {
border-color: rgba(60, 60, 59);
}
.grey-mode {
filter: grayscale(100%);
}
These are my Javascript documents. First, the captcha:
var captcha;
function generate() {
// Clear old input
document.getElementById("submit").value = "";
// Access the element to store
// the generated captcha
captcha = document.getElementById("image");
var uniquechar = "";
const randomchar ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
// Generate captcha for length of
// 5 with random character
for (let i = 1; i < 5; i++) {
uniquechar += randomchar.charAt(
Math.random() * randomchar.length)
}
// Store generated input
captcha.innerHTML = uniquechar;
}
function printmsg() {
const usr_input = document
.getElementById("submit").value;
// Check whether the input is equal
// to generated captcha or not
if (usr_input == captcha.innerHTML) {
var s = document.getElementById("key")
.innerHTML = "Matched";
generate();
}
else {
var s = document.getElementById("key")
.innerHTML = "not Matched";
generate();
}
}
The “grey mode”:
function shadesOfGrey() {
var element = document.body;
element.classList.toggle("grey-mode");
}
The “pink” out:
// to validate before clicking Submit
function validateName(){
var name = document.getElementById("nameBox");
var nameVal = name.value;
if (!//^([^0-9]*)$/.test(nameVal)){
name.style.background = #700064;
} else {
name.style.background = "white";
}
}
The language-change:
"use strict";
var mlCodes = [
{
code: "en",
name: "English",
},
{
code: "it",
name: "Italiano",
},
{
code: "es",
name: "Español",
},
];
var MLstrings = [
{
English: "Validation Page",
Italiano: "Pagina di Validazione",
Español: "Página de validación",
},
{
English: "Name",
Italiano: "Nome",
Español: "Nombre",
},
{
English: "Email",
Italiano: "Indirizzo elettronico",
Español: "Correo electrónico",
},
{
English: "Provider",
Italiano: "Fornitore",
Español: "Proveedor",
},
{
English: "Card",
Italiano: "Carta",