Skip to content

Commit

Permalink
Hide buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
MthoNtanzi committed Mar 23, 2023
1 parent 0fb8ab3 commit 553e22c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ <h1>Now lets play with strings♥</h1>
<div class="stringInput">
<input type="text" placeholder="Enter Your string" id="stringTextBx">
<input type="button" value="Accept" class="button" id="acceptString">
<input type="button" value="New String" class="button" id="newString">
</div>
<section id="stringButtons">
<div>
Expand Down
44 changes: 32 additions & 12 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Hide buttons onload
const arrButtons = document.querySelector('#arrayButtons');
const stringButtons = document.querySelector('#stringButtons');
const newstringBtn = document.querySelector('#newString');


document.addEventListener('DOMContentLoaded', function(){
arrButtons.style.display = 'none';
stringButtons.style.display = 'none';
newstringBtn.style.display = 'none';
viewArrLength.disabled = true;
});

Expand Down Expand Up @@ -50,7 +52,7 @@ insertArr.addEventListener('click',()=>{
var userarrlength = window.prompt("Please enter your array length");

if (userarrlength <= 0 || userarrlength == ''){
window.alert("please enter a valid value")
window.alert("please enter a valid value");
}else{
for(var i = 0;i <= userarrlength-1; i++){
userArr[i] = window.prompt("Enter element "+ i +":");
Expand All @@ -64,6 +66,7 @@ insertArr.addEventListener('click',()=>{
window.alert(text);
viewArrLength.disabled = false;
arrButtons.style.display = 'block';
stringButtons.style.display = 'none'
}

showArr();
Expand Down Expand Up @@ -134,19 +137,26 @@ insertString.addEventListener('click',()=>{
if(stringTextBx.value === '' || stringTextBx.value == ' '){
alert("String is empty\nPlease try again");
}else{
const arrPlayground = document.querySelector('#ArrayPlayground');

alert('String confirmed as: ' + stringTextBx.value);
stringTextBx.disabled = true;
stringTextBx.style.color = '#000';
insertString.style.display = 'none';

arrButtons.style.display = 'none';
stringButtons.style.display = 'block';
insertString.style.display = 'none';
newstringBtn.style.display = 'inline';
viewArrLength.disabled = true;
}
});

newstringBtn.addEventListener('click',()=>{
stringTextBx.value = '';
newstringBtn.style.display ='none';
insertString.style.display = 'inline';
stringTextBx.disabled = false;
})

toUpper.addEventListener('click',()=>{
stringTextBx.style.textTransform = 'uppercase';
});
Expand Down Expand Up @@ -202,14 +212,24 @@ reverseString.addEventListener('click',()=>{
});

maskString.addEventListener('click',()=>{
if(stringTextBx.value.length>=4){
let newStr = '';
let lastTwo = stringTextBx.value.slice(-3);
for(let i=1;i<=stringTextBx.value.length-3;i++){
newStr += '#';
const result = confirm("If you mask the string you won't be able to unmask\nAre you sure you want to continue?");

if (result === true) {
if(stringTextBx.value.length>=4){
let newStr = '';
let lastTwo = stringTextBx.value.slice(-3);
for(let i=1;i<=stringTextBx.value.length-3;i++){
newStr += '#';
}
stringTextBx.value = newStr + lastTwo;

stringButtons.style.display = 'none';

}else{
alert('String is to short to mask')
}
stringTextBx.value = newStr + lastTwo;
}else{
alert('String is to short to mask')
}
} else {
alert("You clicked Cancel.");
}

});

1 comment on commit 553e22c

@vercel
Copy link

@vercel vercel bot commented on 553e22c Mar 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.