Assignment - Buttons

:snail: :butterfly: :bug: :ant: :honeybee: :beetle: :cricket: :duck: :turkey: :hedgehog:
Screenshot 2021-08-10 at 21.19.47

index.html changes
<div id="catColors">

        <button id="colorsButton" type="button" class="btn btn-dark">Colors</button>
        <button id="cattributesButton" type="button" class="btn btn-dark">Cattributes</button>
            <div id="colorsTab" class="form-group">
                <div class="form-group">
                    <label for="formControlRange"><b>Head and body</b><span class="badge badge-dark ml-2" id="headcode"></span></label>
                    <input type="range" min="10" max="98" class="form-control-range" id="bodycolor">
                </div>
            
                <div class="form-group">
                    <label for="formControlRange"><b>Belly and ears</b><span class="badge badge-dark ml-2" id="bellycode"></span></label>
                    <input type="range" min="10" max="98" class="form-control-range" id="bellycolor">
                </div>
                <div class="form-group">
                    <label for="formControlRange"><b>Eye</b><span class="badge badge-dark ml-2" id="eyecode"></span></label>
                    <input type="range" min="10" max="98" class="form-control-range" id="eyecolor">
                </div>
                <div class="form-group">
                    <label for="formControlRange"><b>Pupils</b><span class="badge badge-dark ml-2" id="pupilcode"></span></label>
                    <input type="range" min="10" max="98" class="form-control-range" id="pupilcolor">
                </div>
            </div>
            <div id="cattributesTab" class="form-group">
                <div class="form-group">
                    <label for="formControlRange"><b>Eye shape</b><span class="badge badge-dark ml-2" id="eyeName"></span></label>
                    <input type="range" min="1" max="7" class="form-control-range" id="eyeshape">
                </div>
                <div class="form-group">
                    <label for="formControlRange"><b>Decoration shape</b><span class="badge badge-dark ml-2" id="decorationName"></span></label>
                    <input type="range" min="1" max="7" class="form-control-range" id="decorationshape">
                </div>
                <div class="form-group">
                    <label for="formControlRange"><b>Middle decoration color</b><span class="badge badge-dark ml-2" id="middleDecorationCode"></span></label>
                    <input type="range" min="10" max="98" class="form-control-range" id="middleDecorationColor">
                </div>
                <div class="form-group">
                    <label for="formControlRange"><b>Sides decoration color</b><span class="badge badge-dark ml-2" id="sidesDecorationCode"></span></label>
                    <input type="range" min="10" max="98" class="form-control-range" id="sidesDecorationColor">
                </div>
                <div class="form-group">
                    <label for="formControlRange"><b>Animation</b><span class="badge badge-dark ml-2" id="animationCode"></span></label>
                    <input type="range" min="1" max="4" class="form-control-range" id="animation">
                </div>
            </div>
                <button id="randomButton" type="button" class="btn btn-light">Random kitty</button>
                <button id="defaultButton" type="button" class="btn btn-light">Default kitty</button>
                <button id="createButton" type="button" class="btn btn-light">Create kitty</button>
            </div>
catSettings.js changes
function randomiseDNA(){
  var randomDNA = {
    "headColor" : Math.floor(Math.random() * 89) + 10,
    "bellyColor" : Math.floor(Math.random() * 89) + 10,
    "eyeColor" : Math.floor(Math.random() * 89) + 10,
    "pupilColor" : Math.floor(Math.random() * 89) + 10,
    //Cattributes
    "eyesShape" : Math.floor(Math.random() * 7) + 1,
    "decorationPattern" : Math.floor(Math.random() * 7) + 1,
    "decorationMidcolor" : Math.floor(Math.random() * 89) + 10,
    "decorationSidescolor" : Math.floor(Math.random() * 89) + 10,
    "animation" :  Math.floor(Math.random() * 3) + 1,
    "lastNum" :  1
    }
    renderCat(randomDNA);
}

$('#cattributesButton').click(()=>{
  $('#cattributesTab').show();
  $('#colorsTab').hide();
  
})

$('#colorsButton').click(()=>{
  $('#colorsTab').show();
  $('#cattributesTab').hide();
})

$('#defaultButton').click(()=>{
  renderCat(defaultDNA);
})

$('#randomButton').click(()=>{
  randomiseDNA();
})
1 Like

Job Done

2 Likes

So I broken it, then fixed it and cleaned up.
Here is my reworked code

catsettings.js

`
var colors = Object.values(allColors())

var defaultDNA = {
“headColor” : 10,
“mouthColor” : 13,
“eyesColor” : 23,
“earsColor” : 10,
//Cattributes
“eyesShape” : 1,
“decorationPattern” : 1,
“decorationMidcolor” : 13,
“decorationSidescolor” : 13,
“animation” : 1,
“lastNum” : 1
}

// when page load
$( document ).ready(function() {
defaultKitty()
});

/**

  • Cat settings buttons
    */
    //Random Cat Button
    $(’#randomBtn’).click(() => {
    randomKitty();
    console.log(“random button clicked”);
    })
    //Default Cat Button
    $(’#defaultBtn’).click(() => {
    defaultKitty();
    console.log(“default button clicked”);
    })
    // Create Cat Button
    $(’#createBtn’).click(() => {
    // createKitty();
    console.log(“create button clicked”);
    })

/**

  • Functions
    */
    function defaultKitty() {
    // render the kitty based on default dna
    $(’#dnabody’).html(defaultDNA.headColor);
    $(’#dnamouth’).html(defaultDNA.mouthColor);
    $(’#dnaeyes’).html(defaultDNA.eyesColor);
    $(’#dnaears’).html(defaultDNA.earsColor);

    $(’#dnashape’).html(defaultDNA.eyesShape)
    $(’#dnadecoration’).html(defaultDNA.decorationPattern)
    $(’#dnadecorationMid’).html(defaultDNA.decorationMidcolor)
    $(’#dnadecorationSides’).html(defaultDNA.decorationSidescolor)
    $(’#dnaanimation’).html(defaultDNA.animation)
    $(’#dnaspecial’).html(defaultDNA.lastNum)

    renderCat(defaultDNA)
    }

function randomKitty() {
var randomDNA = {
“headColor” : Math.floor(Math.random() * 89) + 10,
“mouthColor” : Math.floor(Math.random() * 89) + 10,
“eyesColor” : Math.floor(Math.random() * 89) + 10,
“earsColor” : Math.floor(Math.random() * 89) + 10,
//Cattributes
“eyesShape” : Math.floor(Math.random() * 7) + 1,
“decorationPattern” : Math.floor(Math.random() * 6) + 1,
“decorationMidcolor” : Math.floor(Math.random() * 89) + 10,
“decorationSidescolor” : Math.floor(Math.random() * 89) + 10,
“animation” : Math.floor(Math.random() * 7) + 1,
“lastNum” : 1
}

// render the kitty based on the random dna
$('#dnabody').html(randomDNA.headColor);
$('#dnamouth').html(randomDNA.mouthColor);
$('#dnaeyes').html(randomDNA.eyesColor);
$('#dnaears').html(randomDNA.earsColor);
    
$('#dnashape').html(randomDNA.eyesShape)
$('#dnadecoration').html(randomDNA.decorationPattern)
$('#dnadecorationMid').html(randomDNA.decorationMidcolor)
$('#dnadecorationSides').html(randomDNA.decorationSidescolor)
$('#dnaanimation').html(randomDNA.animation)
$('#dnaspecial').html(randomDNA.lastNum)
renderCat(randomDNA)

}

function getDna(){
var dna = ‘’
dna += $(’#dnabody’).html()
dna += $(’#dnamouth’).html()
dna += $(’#dnaeyes’).html()
dna += $(’#dnaears’).html()
dna += $(’#dnashape’).html()
dna += $(’#dnadecoration’).html()
dna += $(’#dnadecorationMid’).html()
dna += $(’#dnadecorationSides’).html()
dna += $(’#dnaanimation’).html()
dna += $(’#dnaspecial’).html()

return parseInt(dna)

}

function renderCat(dna){
headColor(colors[dna.headColor],dna.headColor)
$(’#bodycolor’).val(dna.headColor)
mouthColor(colors[dna.mouthColor],dna.mouthColor)
$(’#mouthcolor’).val(dna.mouthColor)
eyesColor(colors[dna.eyesColor],dna.eyesColor)
$(’#eyescolor’).val(dna.eyesColor)
earsColor(colors[dna.earsColor],dna.earsColor)
$(’#earscolor’).val(dna.earsColor)
eyeVariation(dna.eyesShape)
$(’#eyeshape’).val(dna.eyesShape)
decorationVariation(dna.decorationPattern)
$(’#decorationpattern’).val(dna.decorationPattern)
decorationMidColor(colors[dna.decorationMidcolor],dna.decorationMidcolor)
$(’#decorationmidcolor’).val(dna.decorationMidcolor)
decorationSidesColor(colors[dna.decorationSidescolor],dna.decorationSidescolor)
$(’#decorationsidescolor’).val(dna.decorationSidescolor)
animationVariation(dna.animation)
$(’#animation’).val(dna.animation)
}

// Event listeneners for sliders
// Changing cat colors
$(’#bodycolor’).change(()=>{
var colorVal = $(’#bodycolor’).val()
headColor(colors[colorVal],colorVal)
console.log("body color: " + colorVal)
})
$(’#mouthcolor’).change(()=>{
var colorVal = $(’#mouthcolor’).val()
mouthColor(colors[colorVal],colorVal)
console.log("mouth color: " + colorVal)
})
$(’#eyescolor’).change(()=>{
var colorVal = $(’#eyescolor’).val()
eyesColor(colors[colorVal],colorVal)
console.log("eyes color: " + colorVal)
})
$(’#earscolor’).change(()=>{
var colorVal = $(’#earscolor’).val()
earsColor(colors[colorVal],colorVal)
console.log("ears color: " + colorVal)
})

// Changing cat decoration color
// Middle color
$(’#decorationmidcolor’).change(()=>{
var colorVal = $(’#decorationmidcolor’).val()
decorationMidColor(colors[colorVal],colorVal)
console.log("decoration mid color: " + colorVal)
})
// Sides color
$(’#decorationsidescolor’).change(()=>{
var colorVal = $(’#decorationsidescolor’).val()
decorationSidesColor(colors[colorVal],colorVal)
console.log("decoration sides color: " + colorVal)
})

// Changing cat eye shape
$(’#eyeshape’).change(()=>{
var shape = parseInt( $(’#eyeshape’).val() ) // between 1 and 7
eyeVariation(shape)
console.log("eye shape: " + shape)
})

// Changing cat decoration patterns
$(’#decorationpattern’).change(()=>{
var pattern = parseInt( $(’#decorationpattern’).val() ) // between 1 and 6
decorationVariation(pattern)
console.log("decoration pattern: " + pattern)
})

// Changing cat animation
$(’#animation’).change(()=>{
var animationVal = parseInt( $(’#animation’).val() ) // between 1 and 6
animationVariation(animationVal)
console.log("animation: " + animationVal)
})

`

index.html

`



myKitty Academy kitties





    <link rel="stylesheet" href="assets/css/animations.css">
    <link rel="stylesheet" href="assets/css/mystyle.css">
    <link rel="stylesheet" href="assets/css/cats.css">
    <link rel="stylesheet" href="assets/css/colors.css">
    <link rel="stylesheet" href="assets/css/factory.css">
    <link rel="stylesheet" href="assets/css/frontend.css">
</head>
<body>
    <div class="container p-5" style="margin-top: 12vh;margin-bottom: 10vh;">
        <div align="center">
        <h1 class="c-white">myKitty Kitties-Factory</h1>
        <p class="c-white">Create your custom myKitty</p>
    </div>
    <div class="row">
        <div class="col-lg-5 catBox m-2 light-b-shadow">
            <div class="cat">
                <div id="ears" class="cat__ears">
                    <div class="ear left_ear"></div>
                    <div class="ear right_ear"></div>
                </div>
                <div id="head" class="cat__head" >
                    <div id="midDot" class="cat__head-dots">
                        <div id=" leftDot" class="cat__head-dots_first"></div>
                        <div id=" rightDot" class="cat__head-dots_second"></div>
                    </div>
                    <div id="eye" class="cat__eye">
                        <div class="left_eye">
                            <span class="pupil_left"></span>
                        </div>
                        <div class="right_eye">
                            <span class="pupil_right"></span>
                        </div>
                    </div>
                    <div id="nose" class="cat__nose"></div>
                    <div id="mouth" class="cat__mouth">
                        <div id="tongue" class="cat__tongue"></div>
                    </div>
                </div>
                <div id="tail" class="cat__tail">
                    <div class="tail_shaft"></div>
                    <!-- <div class="tail_flick"></div> -->
                </div>
                <div id="body" class="cat__body">
                    <div class="cat__chest"></div>
                </div>
                <div id="paws" class="cat__paws">
                    <div class="paw left_paw">
                        <div class="toe-pads">
                            <div class="toe-pad1"></div>
                            <div class="toe-pad2"></div>
                            <div class="toe-pad3"></div>
                        </div>
                        <div class="palm-pad"></div>
                    </div>
                    <div class="paw right_paw">
                        <div class="toe-pads">
                            <div class="toe-pad1"></div>
                            <div class="toe-pad2"></div>
                            <div class="toe-pad3"></div>
                        </div>
                        <div class="toe-pad"></div>
                        <div class="palm-pad"></div>
                    </div>
                </div>
            </div>
            <br>
            <div class="dnaDiv" id="catDNA">
                <b>
                    DNA:
                    <!-- Colors -->
                        <span id="dnabody"></span>
                        <span id="dnamouth"></span>
                        <span id="dnaeyes"></span>
                        <span id="dnaears"></span>
                    
                        <!-- Cattributes -->
                        <span id="dnashape"></span>
                        <span id="dnadecoration"></span>
                        <span id="dnadecorationMid"></span>
                        <span id="dnadecorationSides"></span>
                        <span id="dnaanimation"></span>
                        <span id="dnaspecial"></span>
                </b>
            </div>
        </div>
        
        <div class="col-lg-6 cattributes m-2 light-b-shadow"> 
            <!-- Cattributes nav-->
            <nav class="row">
                <div class="nav nav-tabs" id="nav-tab" role="tablist">
                    <a class="nav-item rounded-lg bg-dark text-light nav-link active" 
                        id="nav-colors-tab" 
                        data-toggle="tab" 
                        href="#nav-colors" 
                        role="tab"  
                        aria-controls="nav-colors" 
                        aria-selected="true"> Cat Colors
                    </a>
                    <a class="nav-item rounded-lg bg-dark text-light nav-link" 
                        id="nav-cattributes-tab" 
                        data-toggle="tab" 
                        href="#nav-cattributes" 
                        role="tab"  
                        aria-controls="nav-cattributes" 
                        aria-selected="false"> Cat Attributes
                    </a>
                </div>
            </nav>

            <div class="tab-content" id="nav-tabContent">
                <!-- Cat colors -->
                <div class="tab-pane fade show active" 
                    id="nav-colors" 
                    role="tabpanel" 
                    aria-labelledby="nav-colors-tab">
                    <div id="catColors" class="col-sm-12 cattributeCard m-2 light-b-shadow">
                        <div class="form-group">
                            <label for="formControlRange">
                                <b>Head | Body Color</b>
                                <span class="badge badge-dark ml-2" id="headcode"></span>
                            </label>
                            <input type="range" min="10" max="98" class="form-control-range" id="bodycolor">
                        </div>
                        <div class="form-group">
                            <label for="formControlRange">
                                <b>Mouth | Chest | Tail Color </b>
                                <span class="badge badge-dark ml-2" id="mouthcode"></span>
                            </label>
                            <input type="range" min="10" max="98" class="form-control-range" id="mouthcolor">
                        </div>
                        <div class="form-group">
                            <label for="formControlRange">
                                <b>Eyes Color</b>
                                <span class="badge badge-dark ml-2" id="eyescode"></span>
                            </label>
                            <input type="range" min="10" max="98" class="form-control-range" id="eyescolor">
                        </div>
                        <div class="form-group">
                            <label for="formControlRange">
                                <b>Ears | Paws color</b>
                                <span class="badge badge-dark ml-2" id="earscode"></span>
                            </label>
                            <input type="range" min="10" max="98" class="form-control-range" id="earscolor">
                        </div>
                    </div>
                </div>

                <!-- Cat Attributes -->
                <div class="tab-pane fade" id="nav-cattributes" role="tabpanel" aria-labelledby="nav-cattributes-tab">
                    <div id="catAttributes" class="col-lg-12 cattributeCard m-2 light-b-shadow">
                        
                            <div class="form-group" >
                                <label for="formControlRange">
                                    <b>Eye Shape</b>
                                    <span class="badge badge-dark ml-2" id="eyeName"></span>
                                </label>
                                <input type="range" min="1" max="7" class="form-control-range" id="eyeshape">
                            </div>
                            <div class="form-group">
                                <label for="formControlRange">
                                    <b>Decoration Pattern</b>
                                    <span class="badge badge-dark ml-2" id="decorationName"></span>
                                </label>
                                <input type="range" min="1" max="6" class="form-control-range" id="decorationpattern">
                            </div>
                        
                        <!-- Cat Decoration -->
                        <div id="catDecoration">
                            <div class="form">
                                <b>Decoration Pattern Colors: </b>
                            </div> 
                            <div class="row" >
                                <div class="form-group col">
                                    <label for="formControlRange">
                                        <b>Mid Color</b>
                                        <span class="badge badge-dark ml-2" id="decorationmidcode"></span>
                                    </label>
                                    <input type="range" min="10" max="98" class="form-control-range" id="decorationmidcolor">
                                </div>
                                <div class="form-group col">
                                    <label for="formControlRange">
                                        <b>Sides Color</b>
                                        <span class="badge badge-dark ml-2" id="decorationsidescode"></span>
                                    </label>
                                    <input type="range" min="10" max="98" class="form-control-range" id="decorationsidescolor">
                                </div>
                            </div>
                        </div>
                        <!-- Cat Animations -->
                        <div id="catAnimations">
                            <div class="form-group">
                                <label for="formControlRange">
                                    <b>Animation</b>
                                    <span class="badge badge-dark ml-2" id="animationName"></span>
                                </label>
                                <input type="range" min="1" max="7" class="form-control-range" id="animation">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <br>
    <!-- Buttons -->
    <div id="btnDiv" class="row">
       <div class="btn-group" role="group" aria-label="Action Buttons">
            <button type="button" class="btn m-1 btn-dark" id="randomBtn">Get Random Kitty</button>
            <button type="button" class="btn m-1 btn-dark" id="defaultBtn">Get Default Kitty</button>
            <button type="button" class="btn m-1 btn-success" id="createBtn">Create Kitty</button>
        </div> 
    </div>
    <!-- Kitty creation alert -->
    <div class="alert alert-success" role="alert" id="kittyCreation" style="display: none"></div>
    <br>
    <footer align="left">
        <p>Sean Babb 2021</p>
    </footer>
</body>
<script src="./index.js"></script>
<script src="assets/js/colors.js"></script>
<script src="assets/js/catSettings.js"></script>
<script src="assets/js/catFactory.js"></script>
`
1 Like

Done. And happy to be done with the front-end too! :joy:
https://crypto-cats.netlify.app/

And the code:

index.html
<!DOCTYPE html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CryptoCat</title>
  <script type="text/javascript" src="assets/js/jquery-3.4.1.js"></script>
  <link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
  <script src="assets/bootstrap/js/popper.js"></script>
  <script src="assets/bootstrap/js/bootstrap.min.js"></script>

  <link rel="stylesheet" href="assets/css/mystyle.css">
  <link rel="stylesheet" href="assets/css/cats.css">
  <link rel="stylesheet" href="assets/css/colors.css">
  <link rel="stylesheet" href="assets/css/factory.css">
  <link rel="stylesheet" href="assets/css/frontend.css">
  <link rel="stylesheet" href="assets/css/animations.css">
</head>

<body>
    <div class="container p-6" style="margin-top: 12vh;margin-bottom: 10vh;">
        <div align="center">
        <h1 class="c-white">Cats-Factory</h1>
        <p class="c-white">Create your custom Cat from scratch!</p>
        </div>

        <div class="row">
            <div class="col-lg-5 catBox m-2 light-b-shadow">
                <div class="cat"> 
                    <div class="head">
                        <div class="head_background"></div> 
                        <div class ="ears">
                            <div class="ear_left">
                                <div class="inner_ear_left"></div>
                            </div>
                            <div class="ear_right">
                                <div class="inner_ear_right"></div>
                            </div>
                        </div>
                        <div class="forehead">
                            <div class ="forehead line_left"></div>
                            <div class ="forehead line_right"></div>
                        </div>
                        <div class ="eyes">
                            <div class ="eyes_left">
                                <div class="pupils left"></div>
                                <div class="inner_pupil left"></div>
                                <div class="smaller_inner_pupil left"></div>                                        
                            </div>
                            <div class ="eyes_right">
                                <div class="pupils right"></div>
                                <div class="inner_pupil right"></div>
                                <div class="smaller_inner_pupil right"></div>       
                            </div>
                        </div>
                        <div class="face_body">
                            <div class="nose"></div>
                            <div class="mouth">
                                <div class="mouth_upper"></div>
                                <div class="mouth_lower_right"></div>
                                <div class="mouth_lower_left"></div>
                            </div>
                            <div class="hairs">
                                <div class="hair left top"></div>
                                <div class="hair left middle"></div>
                                <div class="hair left bottom"></div>
                                <div class="hair right top"></div>
                                <div class="hair right middle"></div>
                                <div class="hair right bottom"></div>
                            </div>  
                        </div>    
                    </div>    

                    <div class="body">
                        <div class="collar"></div>
                        <div class="core_body">
                            <div class="inner_body"></div>
                        </div>
                        <div class="feet">
                            <div class="foot front left"></div>
                            <div class="foot front right"></div>
                            <div class="foot back left"></div>
                            <div class="foot back right"></div>
                        </div>
                        <div class="tail">
                            <div class="tail_ball"></div>
                        </div>
                    </div>
                </div>

                <br>

                <div class="dnaDiv" id="catDNA">
                    <b>
                        DNA:
                        <!-- Colors -->
                        <span id="dnabody"></span>
                        <span id="dnamouth"></span>
                        <span id="dnapaws"></span>
                        <span id="dnaeyes"></span>
                        <span id="dnacollar"></span>
                    
                        <!-- Cattributes -->
                        <span id="dnashape"></span>
                        <span id="dnadecoration"></span>
                        <span id="dnadecorationColor"></span>
                        <span id="dnaanimation"></span>

                        <span id="dnaspecial"></span>
                    </b>
                </div>
            </div>

            <div class="col-lg-6 cattributes m-2 light-b-shadow">

                <!-- Tabs -->
                <div align="center">
                    <div class="tabs">
                        <button type="button" class="btn btn-primary catColorsBtn">Cat Colors</button>
                        <button type="button" class="btn btn-primary cattributesBtn">Cattributes</button>
                    </div>
                </div>

                <!-- Cat colors -->
                <div class="tab catColorsBtn">
                    <div class="form-group">
                        <label for="formControlRange"><b>Head and body color</b><span class="badge badge-dark ml-2" id="bodycode"></span></label>
                        <input type="range" min="10" max="98" class="form-control-range" id="bodycolor">
                    </div>
                    <div class="form-group">
                        <label for="formControlRange"><b>Mouth and belly color</b><span class="badge badge-dark ml-2" id="mouthcode"></span></label>
                        <input type="range" min="10" max="98" class="form-control-range" id="mouthcolor">
                    </div>
                    <div class="form-group">
                        <label for="formControlRange"><b>Paws, ears and tail color</b><span class="badge badge-dark ml-2" id="pawscode"></span></label>
                        <input type="range" min="10" max="98" class="form-control-range" id="pawscolor">
                    </div>
                    <div class="form-group">
                        <label for="formControlRange"><b>Eyes and tail-ball color</b><span class="badge badge-dark ml-2" id="eyescode"></span></label>
                        <input type="range" min="10" max="98" class="form-control-range" id="eyescolor">
                    </div>
                    <div class="form-group">
                        <label for="formControlRange"><b>Collar color</b><span class="badge badge-dark ml-2" id="collarcode"></span></label>
                        <input type="range" min="10" max="98" class="form-control-range" id="collarcolor">
                    </div>
                </div>

                <!-- Cattributes -->
                <div class="tab cattributesBtn">
                    <div class="form-group">
                        <label for="formControlRange"><b>Eyes shape</b><span class="badge badge-dark ml-2" id="eyeName"></span></label>
                        <input type="range" min="1" max="6" class="form-control-range" id="eyeshape">
                    </div>
                    <div class="form-group">
                        <label for="formControlRange"><b>Forehead shape</b><span class="badge badge-dark ml-2" id="decorationName"></span></label>
                        <input type="range" min="1" max="5" class="form-control-range" id="decorationshape">
                    </div>
                    <div class="form-group">
                        <label for="formControlRange"><b>Forehead's color</b><span class="badge badge-dark ml-2" id="decorationcode"></span></label>
                        <input type="range" min="10" max="98" class="form-control-range" id="decorationcolor">
                    </div>
                    <div class="form-group">
                        <label for="formControlRange"><b>Animation</b><span class="badge badge-dark ml-2" id="animationName"></span></label>
                        <input type="range" min="1" max="6" class="form-control-range" id="animation">
                    </div>
                </div>
            </div>
        </div>
        <br>
        <div class="row">
            <div align="center" class="col-lg-6 catBox m-2 light-b-shadow">
                <button type="button" class="btn btn-primary default btn-lg">Default DNA</button>
                <button type="button" class="btn btn-warning random btn-lg">Random DNA</button>
            </div>
            <div align="center" class="col-lg-5 catBox m-2 light-b-shadow">
                <button type="button" class="btn btn-success btn-lg btn-block createCat">CREATE</button>
            </div>
        </div>
        <br>
    </div>
        

    <footer align="center">
        <p>
            Ethereum dApp programming - Ivan on Tech Academy - @2021
            <br>
            Designed by: <a href="https://pedrojok01.github.io/">Pedrojok01</a>
        </p>
    </footer>

</body>

<script src="assets/js/colors.js"></script>
<script src="assets/js/catSettings.js"></script>
<script src="assets/js/catFactory.js"></script>

</html>
catSettings.js
var colors = Object.values(allColors())

var defaultDNA = {
    //Colors
    "bodyColor" : 79,
    "mouthColor" : 13,
    "pawsColor" : 20,
    "eyesColor" : 31,
    "collarColor" : 25,
    
    //Cattributes
    "eyesShape" : 1,
    "decorationPattern" : 2,
    "decorationColor" : 67,
    "animation" :  1,

    "lastNum" :  1
    }

// when page load
$( document ).ready(function() {
  defaultPage()
});


// Default DNA value
function defaultPage() {
  $('#dnabody').html(defaultDNA.bodyColor);
  $('#dnamouth').html(defaultDNA.mouthColor);
  $('#dnapaws').html(defaultDNA.pawsColor);
  $('#dnaeyes').html(defaultDNA.eyesColor);
  $('#dnacollar').html(defaultDNA.collarColor)
  $('#dnashape').html(defaultDNA.eyesShape)
  $('#dnadecoration').html(defaultDNA.decorationPattern)
  $('#dnadecorationCollor').html(defaultDNA.decorationColor)
  $('#dnaanimation').html(defaultDNA.animation)
  
  $(".tab.cattributesBtn").hide();
  $(".tab.catColorsBtn").show();

  $('#dnaspecial').html(defaultDNA.lastNum)

  renderCat(defaultDNA)
}


function getDna(){
    var dna = ''
    dna += $('#dnabody').html()
    dna += $('#dnamouth').html()
    dna += $('#dnapaws').html()
    dna += $('#dnaeyes').html()
    dna += $('#dnacollar').html()
    dna += $('#dnashape').html()
    dna += $('#dnadecoration').html()
    dna += $('#dnadecorationCollor').html()
    dna += $('#dnaanimation').html()
    dna += $('#dnaspecial').html()

    return parseInt(dna)
}


function renderCat(dna){
    bodyColor(colors[dna.bodyColor],dna.bodyColor)
    $('#bodycolor').val(dna.bodyColor)
    mouthColor(colors[dna.mouthColor],dna.mouthColor)
    $('#mouthcolor').val(dna.mouthColor)
    pawsColor(colors[dna.pawsColor],dna.pawsColor)
    $('#pawscolor').val(dna.pawsColor)
    eyesColor(colors[dna.eyesColor],dna.eyesColor)
    $('#eyescolor').val(dna.eyesColor)
    collarColor(colors[dna.collarColor],dna.collarColor)
    $('#collarcolor').val(dna.collarColor)
    eyeVariation(dna.eyesShape)
    $('#eyeshape').val(dna.eyesShape)
    decorationVariation(dna.decorationPattern)
    $('#decorationshape').val(dna.decorationPattern)
    decorationColor(colors[dna.decorationColor],dna.decorationColor)
    $('#decorationcolor').val(dna.decorationColor)
    animationVariation(dna.animation)
    $('#animation').val(dna.animation)
}


/*Tabs settings in Cattributes:
*******************************/

$(".btn.catColorsBtn").click(()=>{
  $(".tab.cattributesBtn").hide();
  $(".tab.catColorsBtn").show();
})

$(".btn.cattributesBtn").click(()=>{
  $(".tab.catColorsBtn").hide();
  $(".tab.cattributesBtn").show();
})

$(".btn.default").click(()=>{
  defaultPage();
})

$(".btn.random").click(()=>{
  var randomDNA = {
    "bodyColor" : Math.floor(Math.random() * 89) + 10,
    "mouthColor" : Math.floor(Math.random() * 89) + 10,
    "pawsColor" : Math.floor(Math.random() * 89) + 10,
    "eyesColor" : Math.floor(Math.random() * 89) + 10,
    "collarColor" : Math.floor(Math.random() * 89) + 10,
    "eyesShape" : Math.floor(Math.random() * 6) + 1,
    "decorationPattern" : Math.floor(Math.random() * 5) + 1,
    "decorationColor" : Math.floor(Math.random() * 89) + 10,
    "animation" : Math.floor(Math.random() * 6) + 1,
    "lastNum" : 1
  }
  $('#dnabody').html(randomDNA.bodyColor);
  $('#dnamouth').html(randomDNA.mouthColor);
  $('#dnapaws').html(randomDNA.pawsColor);
  $('#dnaeyes').html(randomDNA.eyesColor);
  $('#dnacollar').html(randomDNA.collarColor);
  $('#dnashape').html(randomDNA.eyesShape);
  $('#dnadecoration').html(randomDNA.decorationPattern);
  $('#dnadecorationCollor').html(randomDNA.decorationColor);
  $('#dnaanimation').html(randomDNA.animation);
  renderCat(randomDNA)
})




/*Colors listeners:
******************/

//Face and body
$('#bodycolor').change(()=>{
    var colorVal = $('#bodycolor').val()
    bodyColor(colors[colorVal],colorVal)
})

//Mouth and belly
$('#mouthcolor').change(()=>{
  var colorVal = $('#mouthcolor').val()
  mouthColor(colors[colorVal],colorVal)
})

//Paws, ears and tail
$('#pawscolor').change(()=>{
  var colorVal = $('#pawscolor').val()
  pawsColor(colors[colorVal],colorVal)
})

//Eyes, collar and tail-ball
$('#eyescolor').change(()=>{
  var colorVal = $('#eyescolor').val()
  eyesColor(colors[colorVal],colorVal)
})

//Collar color
$('#collarcolor').change(()=>{
  var colorVal = $('#collarcolor').val()
  collarColor(colors[colorVal],colorVal)
})



/*Cattributes listeners:
************************/

//Eyes shape
$('#eyeshape').change(()=>{
  var shape = parseInt($('#eyeshape').val())
  eyeVariation(shape)
})

//Decorations
$('#decorationshape').change(()=>{
  var decoShape = parseInt($('#decorationshape').val())
  decorationVariation(decoShape)
})

//Decorations color
$('#decorationcolor').change(()=>{
  var colorVal = $('#decorationcolor').val()
  decorationColor(colors[colorVal],colorVal)
})

//Animations
$('#animation').change(()=>{
  var animationVal = parseInt($('#animation').val())
  animationVariation(animationVal)
})

2 Likes

Hey Carlos, sorry for taking so long to get back to you, I’m juggling between the assignments and getting to learn more about truffle config in VS and ganache Eth on Metamask. So much to learn. Oh well, here you can check all that I have regarding this assignment. I don’t know why some slides are not working at all, I mean, no change is visible as I move throughout the slides. Could you please let me know what am I missing out?
Thank you very much,
Maia
https://github.com/Maiajc/Assig01.git

Hi all,
I can’t figure out, why Random cat button doesn’t work for cat attributes, but for cat colors it works?

index.html

<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Academy kitties </title>
  <script type="text/javascript" src="assets/js/jquery-3.4.1.js"></script>
  <link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
  <script src="assets/bootstrap/js/popper.js"></script>
  <script src="assets/bootstrap/js/bootstrap.min.js"></script>

  <link rel="stylesheet" href="assets/css/mystyle.css">
  <link rel="stylesheet" href="assets/css/cats.css"> 
  <!--<link rel="stylesheet" href="assets/css/MyCat.css"> -->
  <link rel="stylesheet" href="assets/css/colors.css">
  <link rel="stylesheet" href="assets/css/factory.css">
  <link rel="stylesheet" href="assets/css/frontend.css">
  <link rel="stylesheet" href="assets/css/animation.css">
 

</head>
  <body>
    <div class="container p-5" style="margin-top: 12vh;margin-bottom: 10vh;">
        <div align="center">
        <h1 class="c-white">Kitties-Factory</h1>
        <p class="c-white">Create your custom Kitty</p>
    </div>
        <div class="row">
            <div class="col-lg-4 catBox m-2 light-b-shadow">
                <div class="cat">
                    <div class="cat__ear">
                        <div id="leftEar" class="cat__ear--left">
                            <div class="cat__ear--left-inside"></div>
                        </div>
                        <div id="rightEar" class="cat__ear--right">
                            <div class="cat__ear--right-inside"></div>
                        </div>
                    </div>

                    <div id="head" class="cat__head">
                        <div id="midDot" class="cat__head-dots">
                            <div id="leftDot" class="cat__head-dots_first"></div>
                            <div id="rightDot" class="cat__head-dots_second"></div>
                        </div>
                        <div class="cat__eye">
                            <div class="cat__eye--left">
                                <span class="pupil-left"></span>
                            </div>
                            <div class="cat__eye--right">
                                <span class="pupil-right"></span>
                            </div>
                        </div>
                        <div class="cat__nose"></div>

                        <div class="cat__mouth-contour"></div>
                        <div class="cat__mouth-left"></div>
                        <div class="cat__mouth-right"></div>

                        <div class="cat__whiskers-left"></div>
                        <div class="cat__whiskers-right"></div>
                    </div>

                    <div class="cat__body">

                        <div class="cat__chest"></div>

                        <div class="cat__chest_inner"></div>


                        <div class="cat__paw-left"></div>
                        <div class="cat__paw-left_inner"></div>


                        <div class="cat__paw-right"></div>
                        <div class="cat__paw-right_inner"></div>


                        <div id="tail" class="cat__tail"></div>
                    </div>
                </div>
                <br>
                <div class="dnaDiv" id="catDNA">
                    <b>
                        DNA:
                        <!-- Colors -->
                         <span id="dnabody"></span>
                         <span id="dnamouth"></span>
                         <span id="dnaeyes"></span>
                         <span id="dnaears"></span>
                        
                         <!-- Cattributes -->
                         <span id="dnashape"></span>
                         <span id="dnadecoration"></span>
                         <span id="dnadecorationMid"></span>
                         <span id="dnadecorationSides"></span>
                         <span id="dnadanimation"></span>
                         <span id="dnaspecial"></span>
                    </b>
                </div>
            </div>
            <div class="col-lg-7 cattributes m-2 light-b-shadow">
                <button id="btnColor" type="button"> Cat colors</button>
                <button id="btnAttributes" type="button"> Cattributes</button>
                <button id="btnDefault" type="button"> Default cat</button>
                <button id="btnRandom" type="button"> Random cat</button>
                <button id="btnCreate" type="button"> Create cat</button>
                <!-- Cat colors -->
                <div id="catColors">
                   
                    <div id="headGroup" class="form-Group">
                        <label for="formControlRange"><b>Head and body</b><span class="badge badge-dark ml-2" id="headcode"></span></label>
                        <input type="range" min="10" max="98" class="form-control-range" id="bodycolor">
                    </div>
                    <div id="earGroup" class="form-group">
                        <label for="formControlRange"><b>Ears</b><span class="badge badge-dark ml-2" id="earcode"></span></label>
                        <input type="range" min="10" max="98" class="form-control-range" id="earcolor">
                    </div>
                    <div id="mouthGroup" class="form-group">
                        <label for="formControlRange"><b>Mouth and tail</b><span class="badge badge-dark ml-2" id="mouth_contour_code"></span></label>
                        <input type="range" min="10" max="98" class="form-control-range" id="mouth_contour_color">
                    </div>
                    <div id="eyeColorGroup" class="form-group"></div>
                        <label for="formControlRange"><b>Eye</b><span class="badge badge-dark ml-2" id="eyecode"></span></label>
                        <input type="range" min="10" max="98" class="form-control-range" id="eyecolor">
                    </div>
                    <div id="eyeShapeGroup" class="form-group">
                        <label for="formControlRange"><b>Eye shape</b><span class="badge badge-dark ml-2" id="eyeName"></span></label>
                        <input type="range" min="1" max="5" class="form-control-range" id="eyeShape">
                    </div>
                    <div id="decorGroup" class="form-group">
                        <label for="formControlRange"><b>Decoration</b><span class="badge badge-dark ml-2" id="decorationName"></span></label>
                        <input type="range" min="1" max="4" class="form-control-range" id="decoration">
                    </div>
                    <div id="midDecorGroup" class="form-group">
                        <label for="formControlRange"><b>Mid decoration</b><span class="badge badge-dark ml-2" id="midDecorName"></span></label>
                        <input type="range" min="10" max="98" class="form-control-range" id="midDecor">
                    </div>
                    <div id="LRdecorGroup" class="form-group">
                        <label for="formControlRange"><b>Left - Right decoration</b><span class="badge badge-dark ml-2" id="leftRightDecorName"></span></label>
                        <input type="range" min="10" max="98" class="form-control-range" id="leftRightDecor">
                    </div>
                    <div id="animationGroup" class="form-group">
                        <label for="formControlRange"><b>Animation</b><span class="badge badge-dark ml-2" id="animationName"></span></label>
                        <input type="range" min="1" max="4" class="form-control-range" id="animations">
                    </div>
                </div>

            </div>

            </div>
            <br>

        </div>



    </div>
    <footer align="left">
        <p>Ivan on Tech Academy Bootcamp July 2020</p>
    </footer>

  </body>
  <script src="assets/js/colors.js"></script>
  <script src="assets/js/catSettings.js"></script>
  <script src="assets/js/catFactory.js"></script>

</html>

catSettings.js


var colors = Object.values(allColors())

var defaultDNA = {
    "headcolor" : 10,
    "mouthColor" : 13,
    "eyesColor" : 96,
    "earsColor" : 10,
    //Cattributes
    "eyesShape" : 1,
    "decorationPattern" : 1,
    "decorationMidcolor" : 13,
    "decorationSidescolor" : 13,
    "animation" :  1,
    "lastNum" :  1
    }

// when page load
$( document ).ready(function() {
  $('#dnabody').html(defaultDNA.headColor);
  $('#dnamouth').html(defaultDNA.mouthColor);
  $('#dnaeyes').html(defaultDNA.eyesColor);
  $('#dnaears').html(defaultDNA.earsColor);
    
  $('#dnashape').html(defaultDNA.eyesShape)
  $('#dnadecoration').html(defaultDNA.decorationPattern)
  $('#dnadecorationMid').html(defaultDNA.decorationMidcolor)
  $('#dnadecorationSides').html(defaultDNA.decorationSidescolor)
  $('#dnaanimation').html(defaultDNA.animation)
  $('#dnaspecial').html(defaultDNA.lastNum)

  renderCat(defaultDNA)
});

function getDna(){
    var dna = ''
    dna += $('#dnabody').html()
    dna += $('#dnamouth').html()
    dna += $('#dnaeyes').html()
    dna += $('#dnaears').html()
    dna += $('#dnashape').html()
    dna += $('#dnadecoration').html()
    dna += $('#dnadecorationMid').html()
    dna += $('#dnadecorationSides').html()
    dna += $('#dnaanimation').html()
    dna += $('#dnaspecial').html()

    return parseInt(dna)
}

function renderCat(dna){
    headColor(colors[dna.headcolor],dna.headcolor)
    $('#bodycolor').val(dna.headcolor)
    earColor(colors[dna.earsColor],dna.earsColor)
    $('#earcolor').val(dna.earsColor)
    mouth_contour_Color(colors[dna.mouthColor],dna.mouthColor)
    $('#mouth_contour_color').val(dna.mouthColor)
    eyeColor(colors[dna.eyesColor],dna.eyesColor)
    $('#eyecolor').val(dna.eyesColor)
    eyeVariation.val(dna.eyesShape)
    $('#eyeShape').val(dna.eyesShape)
    decorationVariation.val(dna.decorationPattern)
    $('#decoration').val(dna.decorationPattern)
    midDecorColor.val(colors[dna.decorationMidcolor], dna.decorationMidcolor)
    $('#midDecor').val(dna.decorationMidcolor)
    LeftRightDecorColor(colors[dna.decorationSidescolor], dna.decorationSidescolor)
    $('#leftRightDecor').val(dna.decorationSidescolor)
    animationFun.val(dna.animation)
    $('#animations').val(dna.animation)
}

// Changing cat colors
$('#bodycolor').change(()=>{
    var colorVal = $('#bodycolor').val()
    headColor(colors[colorVal],colorVal)
})

$('#earcolor').change(()=>{
  var colorVal = $('#earcolor').val()
  earColor(colors[colorVal],colorVal)
})

$('#mouth_contour_color').change(()=>{
  var colorVal = $('#mouth_contour_color').val()
  mouth_contour_Color(colors[colorVal],colorVal)
})

$('#eyecolor').change(()=>{
  var colorVal = $('#eyecolor').val()
  eyeColor(colors[colorVal],colorVal)
})

$('#eyeShape').change(()=>{
  var shape = parseInt($('#eyeShape').val())
  eyeVariation(shape)
})

$('#decoration').change(()=>{
  var decoration = parseInt($('#decoration').val())
  decorationVariation(decoration)
})

$('#midDecor').change(()=>{
  var decorationMid = $('#midDecor').val()
  midDecorColor(colors[decorationMid],decorationMid)
})

$('#leftRightDecor').change(()=>{
  var decorationLR = $('#leftRightDecor').val()
  LeftRightDecorColor(colors[decorationLR],decorationLR)
})

$('#animations').change(()=>{
  var animationValue = parseInt($('#animations').val())
  animationFun(animationValue)
})

$('#btnColor').click(()=>{
  $('#headGroup').show()
  $('#earGroup').show()
  $('#mouthGroup').show()
  $('#eyeColorGroup').show()

  $('#eyeShapeGroup').hide()
  $('#decorGroup').hide()
  $('#midDecorGroup').hide()
  $('#LRdecorGroup').hide()
  $('#animationGroup').hide()
})

$('#btnAttributes').click(()=>{
  $('#headGroup').hide()
  $('#earGroup').hide()
  $('#mouthGroup').hide()
  $('#eyeColorGroup').hide()

  $('#eyeShapeGroup').show()
  $('#decorGroup').show()
  $('#midDecorGroup').show()
  $('#LRdecorGroup').show()
  $('#animationGroup').show()
})

$('#btnDefault').click(()=>{
  renderCat(defaultDNA);
})

$('#btnRandom').click(()=>{
  var Random = {
    //Cat colors
    "headcolor" : Math.floor(Math.random() * 89) + 10,
    "eyesColor" : Math.floor(Math.random() * 89) + 10,
    "earsColor" : Math.floor(Math.random() * 89) + 10,
    "mouthColor" : Math.floor(Math.random() * 89) + 10,
    //Cat attributes
    "eyesShape" : Math.floor(Math.random() * 5) + 1,
    "decorationPattern" : Math.floor(Math.random() * 4) + 1,
    "decorationMidcolor" : Math.floor(Math.random() * 89) + 10,
    "decorationSidescolor" : Math.floor(Math.random() * 89) + 10,
    "animation" : Math.floor(Math.random() * 4) + 1,
  }
  $('#dnabody').html(Random.headcolor);
  $('#dnaeyes').html(Random.eyesColor);
  $('#dnaears').html(Random.earsColor);
  $('#dnamouth').html(Random.mouthColor);

  $('#dnashape').html(Random.eyesShape);
  $('#dnadecoration').html(Random.decorationPattern);
  $('#dnadecorationMid').html(Random.decorationMidcolor);
  $('#dnadecorationSides').html(Random.decorationSidescolor);
  $('#dnaanimation').html(Random.animation);
  renderCat(Random)
})


hey @Lane11 ! Look at this

Is different id from the one you are using with Jquery

The rest looks good and should work. Please check if it is any errors in the console and send me a picture. Also make a console.log(Random ) to see the results from maths functions and check that everything is ok

1 Like

Here’s my code. I just added the relevant code.

index
//The two buttons that switch between Colours and Cattributes
<div id="toggleButtons">                
    <button type="button" onclick="showColours()" class="btn btn-primary">Colours</button>
    <button type="button" onclick="showCattributes()" class="btn btn-primary">Cattributes</button>
</div>
//The three buttons that create a random, a default and a new kitty
<div class="catCreations">
    <button type="button"  onclick="createDefaultKitty()" class="btn btn-success">Create Default Kitty</button>
    <button type="button"  onclick="createRandomKitty()" class="btn btn-danger">Create Random Kitty</button>
    <button type="button"  onclick="showColours()" class="btn btn-warning">Create Actual Kitty</button>
</div>
factory.css
//I used flexbox to space the creation buttons
.catCreations {
    display: flex;
    justify-content: space-around;
}
catFactory.js
//Toggling between Colours and Cattributes
function showColours() {
    $('#catColors').show();
    $('#catCattributes').hide();
}

function showCattributes() {
    $('#catCattributes').show();
    $('#catColors').hide();
}
catSettings.js
//The two functions that create a random cat and the default cat

//Create Default Cat
function createDefaultKitty() {
    renderCat(defaultDNA)
}
//Create Random Cat
function createRandomKitty() {
    //Create a rounded down number from 10 to 98
    var numHead = Math.floor(Math.random() * 89) + 10;
    headColor(colors[numHead], numHead)
    $('#bodycolor').val(numHead)

    var numPaw = Math.floor(Math.random() * 89) + 10;
    earPawFeetColor(colors[numPaw], numPaw)
    $('#earPawFeetcolor').val(numPaw)

    var numTummy = Math.floor(Math.random() * 89) + 10;
    tummyMouthAreaColor(colors[numTummy], numTummy)
    $('#tummyMouthAreacolor').val(numTummy)

    var numEyes = Math.floor(Math.random() * 89) + 10;
    eyeColor(colors[numEyes], numEyes)
    $('#eyecolor').val(numEyes)

    var numEyesShape = Math.floor(Math.random() * 10) + 1;
    eyeVariation(numEyesShape)
    $('#eyeshape').val(numEyesShape)

    var numDecorationPattern = Math.floor(Math.random() * 10) + 1;
    decorationVariation(numDecorationPattern)
    $('#decorationshape').val(numDecorationPattern)

    var numTopBottomDecoration = Math.floor(Math.random() * 89) + 10;
    topBottomDecorationColor(colors[numTopBottomDecoration], numTopBottomDecoration)
    $('#topBottomDecorationcolor').val(numTopBottomDecoration)

    var numMiddleDecoration = Math.floor(Math.random() * 89) + 10;
    middleDecorationColor(colors[numMiddleDecoration], numMiddleDecoration)
    $('#middleDecorationcolor').val(numMiddleDecoration)

    var numAnimation = Math.floor(Math.random() * 10) + 1;
    animationVariation(numAnimation)
    $('#animation').val(numAnimation)
}
2 Likes

kitty

index.html

...
    <div class="cardsRow">
        <div class="cardsColumn">
            <div class="card" style="width: 18rem;">
                <div class="card-body">
                  <h5 class="card-title">Colors</h5>
                  <p class="card-text">Choose the colors for your cat.</p>
                  <div class="form-group">
                    <label for="formControlRange"><b>Head & Body</b><span class="badge badge-dark ml-2" id="headcode"></span></label>
                    <input type="range" min="10" max="98" class="form-control-range" id="bodycolor">
                </div>
                <div class="form-group">
                    <label for="formControlRange"><b>Mouth, Tail & Belly</b><span class="badge badge-dark ml-2" id="mouthcode"></span></label>
                    <input type="range" min="10" max="98" class="form-control-range" id="mouthcolor">
                </div>
                <div class="form-group">
                    <label for="formControlRange"><b>Eyes</b><span class="badge badge-dark ml-2" id="eyescode"></span></label>
                    <input type="range" min="10" max="98" class="form-control-range" id="eyescolor">
                </div>
                <div class="form-group">
                    <label for="formControlRange"><b>Ears & Paws</b><span class="badge badge-dark ml-2" id="earscode"></span></label>
                    <input type="range" min="10" max="98" class="form-control-range" id="earscolor">
                </div>
                </div>
              </div>
        </div>
        <div class="cardsColumn">
            <div class="card" style="width: 18rem;">
                <div class="card-body">
                  <h5 class="card-title">Shapes, Styles & Extras</h5>
                  <div class="form-group">
                    <label for="formControlRange"><b>Eyes Shape</b><span class="badge badge-dark ml-2" id="eyeName"></span></label>
                    <input type="range" min="1" max="3" class="form-control-range" id="eyeshape">
                </div>
                <div class="form-group">
                    <label for="formControlRange"><b>Decoration Style</b><span class="badge badge-dark ml-2" id="decorationName"></span></label>
                    <input type="range" min="1" max="3" class="form-control-range" id="decorationPattern">
                </div>
                <div class="form-group">
                    <label for="formControlRange"><b>Decoration Color 1</b><span class="badge badge-dark ml-2" id="decorationCode1"></span></label>
                    <input type="range" min="10" max="98" class="form-control-range" id="decorationColor1">
                </div>
                <div class="form-group">
                    <label for="formControlRange"><b>Decoration Color 2</b><span class="badge badge-dark ml-2" id="decorationCode2"></span></label>
                    <input type="range" min="10" max="98" class="form-control-range" id="decorationColor2">
                </div>
                <div class="form-group">
                    <label for="formControlRange"><b>Animation</b><span class="badge badge-dark ml-2" id="animationName"></span></label>
                    <input type="range" min="1" max="4" class="form-control-range" id="animations">
                </div>
                </div>
              </div>
        </div>
      </div>
      <br>
    <button type="button" id="randomKitty" class="btn btn-primary">Random Kitty</button>
    <button type="button" id="defaultKitty" class="btn btn-secondary">Default Kitty</button>
    <button type="button" id="createKitty" class="btn btn-success">Create Kitty</button>
...

frontend.css

...
.cardsColumn {
  float: left;
  width: 50%;
}

/* Clear floats after the columns */
.cardsRow:after {
  content: "";
  display: table;
  clear: both;
}
...

catSettings.js

...
function randomizeDna() {
  let customDNA = {
    headcolor: Math.floor(Math.random() * 89) + 10, //10-98
    mouthColor: Math.floor(Math.random() * 89) + 10, //10-98
    eyesColor: Math.floor(Math.random() * 89) + 10, //10-98
    earsColor: Math.floor(Math.random() * 89) + 10, //10-98
    eyesShape: Math.floor(Math.random() * 3) + 1, // 1-3
    decorationPattern: Math.floor(Math.random() * 3) + 1, // 1-3
    decorationMidcolor: Math.floor(Math.random() * 89) + 10, //10-98
    decorationSidescolor: Math.floor(Math.random() * 89) + 10, //10-98
    animation: Math.floor(Math.random() * 4) + 1, //1-4
    lastNum: Math.floor(Math.random() * 5) +1, // 1-2
  };
  renderCat(customDNA)
}

$("#randomKitty").click(function () {
  randomizeDna();
});

$("#defaultKitty").click(function () {
  renderCat(defaultDNA)
});

$("#createKitty").click(function () {
  //todo
});
...
1 Like

Here’s the frontend:

Screen Shot 2021-10-12 at 11.43.42 PM

This is a GIF but may only loop once - open this image in a new tab to view the colors in action.

screencapture

changed code in catSettings.js

// Reset DNA
$('#btn_reset').click(function() {
      renderCat(defaultDNA)
})



// Random DNA
$('#btn_randomize').click(function() {
      var bodyColorRandom = Math.floor(Math.random() * 89) + 10;
      headColor(colors[bodyColorRandom], bodyColorRandom)
      $('#bodycolor').val(bodyColorRandom)

      var tailColorRandom = Math.floor(Math.random() * 89) + 10;
      tailColor(colors[tailColorRandom], tailColorRandom)
      $('#tailcolor').val(tailColorRandom)

      var maneColorRandom = Math.floor(Math.random() * 89) + 10;
      maneColor(colors[maneColorRandom], maneColorRandom)
      $('#manecolor').val(maneColorRandom)

      var eyesColorRandom = Math.floor(Math.random() * 89) + 10;
      eyesColor(colors[eyesColorRandom], eyesColorRandom)
      $('#eyescolor').val(eyesColorRandom)

      var decorColorRandom = Math.floor(Math.random() * (70 - 60)) + 60;
      linesColor(colors[decorColorRandom], decorColorRandom)
      $('#linedircolor').val(decorColorRandom)

      var eyesShapeRandom = Math.floor(Math.random() * (4 - 1)) + 1;
      eyeVariation(eyesShapeRandom)
      $('#eyeshape').val(eyesShapeRandom)

      var decorShapeRandom = Math.floor(Math.random() * (4 - 1)) + 1;
      decorationVariation(decorShapeRandom)
      $('#linedir').val(decorShapeRandom)

      var anim1Random = Math.floor(Math.random() * (3 - 1)) + 1;
      animationVariation1(anim1Random)
      $('#animation1').val(anim1Random)

      var anim2Random = Math.floor(Math.random() * (3 - 1)) + 1;
      animationVariation2(anim2Random)
      $('#animation2').val(anim2Random)
})

1 Like

the functions:


$('#ColorsTab').click(()=>{
    $("#headSlider").show()
    $("#eyesSlider").show()
    $("#pawsSlider").show()
    $("#stripesSlider").show()

    $("#eyeStyleSlider").hide();
    $("#stripesStyleSlider").hide();
    $("#bellySlider").hide();
    $("#jowlsSlider").hide();
    $("#animationSlider").hide();
})
$('#CattributesTab').click(()=>{
    $("#headSlider").hide()
    $("#eyesSlider").hide()
    $("#pawsSlider").hide()
    $("#stripesSlider").hide()

    $("#eyeStyleSlider").show();
    $("#stripesStyleSlider").show();
    $("#bellySlider").show();
    $("#jowlsSlider").show();
    $("#animationSlider").show();
})

$('#random').click(()=>{
    var ran_head = Math.floor(Math.random() * 89) + 10;
    headColor(colors[ran_head], ran_head)
    $("#bodycolor").val(ran_head)
    var ran_eye = Math.floor(Math.random() * 89) + 10;
    eyeColor(colors[ran_eye],ran_eye)
    $('#eyecolor').val(ran_eye)
    var ran_paw = Math.floor(Math.random() * 89) + 10;
    pawsColor(colors[ran_paw],ran_paw)
    $('#pawscolor').val(ran_paw)
    var ran_stripe = Math.floor(Math.random() * 89) + 10;
    stripesColor(colors[ran_stripe],ran_stripe)
    $('#stripescolor').val(ran_stripe)
    var ran_eyeshape = Math.floor(Math.random() * 8) + 1;
    eyeVariation(ran_eyeshape)
    $('#eyeshape').val(ran_eyeshape)
    var ran_stripeShape = Math.floor(Math.random() * 8) + 1;
    decorationVariation(ran_stripeShape)
    $('#decorationshape').val(ran_stripeShape)
    var ran_belly = Math.floor(Math.random() * 41) + 10;
    bellyColor(colorsB[ran_belly],ran_belly)
    $('#bellycolor').val(ran_belly)
    var ran_jowls = Math.floor(Math.random() * 41) + 10;
    jowlsColor(colorsB[ran_jowls],ran_jowls)
    $('#jowlscolor').val(ran_jowls)
    var ran_animation = Math.floor(Math.random() * 8) + 1;
    animationVariation(ran_animation)
    $('#animationType').val(ran_animation)
})

$('#reset').click(()=>{

    headColor(colors[defaultDNA.headcolor],defaultDNA.headcolor)
    $("#bodycolor").val(defaultDNA.headcolor)
    eyeColor(colors[defaultDNA.eyecolor],defaultDNA.eyecolor)
    $("#eyecolor").val(defaultDNA.eyecolor)
    pawsColor(colors[defaultDNA.pawscolor],defaultDNA.pawscolor)
    $("#pawscolor").val(defaultDNA.pawscolor)
    stripesColor(colors[defaultDNA.stripescolor],defaultDNA.stripescolor)
    $("#stripescolor").val(defaultDNA.stripescolor)
    eyeVariation(defaultDNA.eyeshape)
    $("#eyeshape").val(defaultDNA.eyeshape)
    decorationVariation(defaultDNA.decorationshape)
    $("#decorationshape").val(defaultDNA.decorationshape)
    bellyColor(colorsB[defaultDNA.bellycolor],defaultDNA.bellycolor)
    $("#bellycolor").val(defaultDNA.bellycolor)
    jowlsColor(colorsB[defaultDNA.jowlscolor],defaultDNA.jowlscolor)
    $("#jowlscolor").val(defaultDNA.jowlscolor)
    animationVariation(defaultDNA.animation)
    $("#animationType").val(defaultDNA.animation)

})

Here are my additions

Index.html

 <!-- Cat colors -->
            <div id="catColors">
                <ul class="nav nav-pills nav-justified" id="myTab" role="tablist">
                    <li class="nav-item">
                      <a class="nav-link active" id="colors-tab" data-toggle="pill" href="#color" role="tab" aria-controls="color" aria-selected="true">Colors</a>
                    </li>
                    <li class="nav-item">
                      <a class="nav-link" id="cattributes-tab" data-toggle="pill" href="#cattribute" role="tab" aria-controls="cattribute" aria-selected="false">Cattributes</a>
                    </li>
                </ul>

                <div class="tab-content" id="myTabContent">
                    <div class="tab-pane fade show active" id="color" role="tabpanel" aria-labelledby="colors-tab">
                        <br>
                        <div class="form-group">
                            <label for="formControlRange"><b>Head and Body</b><span class="badge badge-dark ml-2" id="headcode"></span></label>
                            <input type="range" min="1" max="98" class="form-control-range" id="bodycolor">
                        </div><div class="form-group">
                            <label for="formControlRange"><b>Mouth, Belly and Tail</b><span class="badge badge-dark ml-2" id="mouthcode"></span></label>
                            <input type="range" min="1" max="98" class="form-control-range" id="mouthcolor">
                        </div>
                        <div class="form-group">
                            <label for="formControlRange"><b>Eyes</b><span class="badge badge-dark ml-2" id="eyescode"></span></label>
                            <input type="range" min="1" max="98" class="form-control-range" id="eyescolor">
                        </div>
                        <div class="form-group">
                            <label for="formControlRange"><b>Ears</b><span class="badge badge-dark ml-2" id="earscode"></span></label>
                            <input type="range" min="1" max="98" class="form-control-range" id="earscolor">
                        </div>
                        <div class="form-group">
                            <label for="formControlRange"><b>Middle Color</b><span class="badge badge-dark ml-2" id="decorationMidColor"></span></label>
                            <input type="range" min="1" max="98" class="form-control-range" id="decorationmid">
                        </div>
                        <div class="form-group">
                            <label for="formControlRange"><b>Outside Color</b><span class="badge badge-dark ml-2" id="decorationSideColor"></span></label>
                            <input type="range" min="1" max="98" class="form-control-range" id="decorationside">
                        </div>
                        
                    </div>
                    <div class="tab-pane fade" id="cattribute" role="tabpanel" aria-labelledby="cattributes-tab">
                        <br>
                        <div class="form-group">
                            <label for="formControlRange"><b>Decorative</b><span class="badge badge-dark ml-2" id="decorationName"></span></label>
                            <input type="range" min="1" max="9" class="form-control-range" id="decorationshape">
                        </div>
                        
                        <div class="form-group">
                            <label for="formControlRange"><b>Eyes Shape</b><span class="badge badge-dark ml-2" id="eyeName"></span></label>
                            <input type="range" min="1" max="7" class="form-control-range" id="eyeshape">
                        </div>
                        <div class="form-group">
                            <label for="formControlRange"><b>Animation</b><span class="badge badge-dark ml-2" id="animationName"></span></label>
                            <input type="range" min="1" max="6" class="form-control-range" id="animation">
                        </div>
                    </div>
                </div>
            </div>
            
            <b>

           <div class="buttons">
            <button type="button" id="defaultKitty" class="btn btn-outline-primary">Default Kitty</button>
            <button type="button" id="randomKitty" class="btn btn-outline-warning">Random Kitty</button>
            <button type="button" id="newKitty" class="btn btn-outline-success">New Kitty</button>
           </div>
           </b>
        </div>

catSettings.js

$('#defaultKitty').click(()=>{
  renderCat(defaultDNA);
});

var getRandomLarge = () =>{
  return (Math.floor(Math.random() * 98) + 1);
}
var getRandomSmall1 = () =>{
  return (Math.floor(Math.random() * 6) + 1);
}
var getRandomSmall2 = () =>{
  return (Math.floor(Math.random() * 7) + 1);
}
var getRandomSmall3 = () =>{
  return (Math.floor(Math.random() * 9) + 1);
}

$('#randomKitty').click(()=>{
  var randomDNA = {
    "headColor" : getRandomLarge(),
    "mouthColor" : getRandomLarge(),
    "eyesColor" : getRandomLarge(),
    "earsColor" : getRandomLarge(),
    //Cattributes
    "eyesShape" : getRandomSmall2(),
    "decorationPattern" : getRandomSmall3(),
    "decorationMidColor" : getRandomLarge(),
    "decorationSideColor" : getRandomLarge(),
    "animation" : getRandomSmall3(),
    "lastNum" : 1
    }
  renderCat(randomDNA);
});

1 Like

This was good fun.
What I did was:

  1. Made two tabs for colors and cattributes - supported by bootstrap pills.
  2. Set Up 3 bootstrap buttons on the button of the from - labelled Reset Kitty, Randomize Kitty, and Mint Kitty. All pretty self-explanatory.
  3. Then I set up a new file called frontendFunctions.js which to help control the buttons and tabs.

I made a concerted effort to not hardcode anything if it didn’t need to be.
So this meant with the randomizer, that it was fetching the min and max props from the inputs in on the index.html to put into the Math.random() function.

Here is how the interface looks:

Here is the Code:

index.html

<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Academy kitties </title>
  <script type="text/javascript" src="assets/js/jquery-3.4.1.js"></script>
  <link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
  <script src="assets/bootstrap/js/popper.js"></script>
  <script src="assets/bootstrap/js/bootstrap.min.js"></script>

  <link rel="stylesheet" href="assets/css/mystyle.css">
  <link rel="stylesheet" href="assets/css/cats.css">
  <link rel="stylesheet" href="assets/css/colors.css">
  <link rel="stylesheet" href="assets/css/factory.css">
  <link rel="stylesheet" href="assets/css/frontend.css">
  <link rel="stylesheet" href="assets/css/animations.css">
</head>
  <body>
    <div class="container p-5" style="margin-top: 12vh;margin-bottom: 10vh;">
        <div align="center">
        <h1 class="c-white">Kreative Kitties</h1>
        <p class="c-white">Kreate A Kustom Kitty</p>
    </div>
        <div class="row">
            <div class="col-lg-4 catBox m-2 light-b-shadow">
                <div class="cat">
                    <div class="cat__ear breathing">
                        <div id="leftEar" class="cat__ear--left">
                            <div class="cat__ear--left-inside"></div>
                        </div>
                        <div id="rightEar" class="cat__ear--right">
                            <div class="cat__ear--right-inside"></div>
                        </div>
                    </div>

                    <div id="head" class="cat__head breathing">
                        <div id="midDot" class="cat__head-dots">
                            <div id="leftDot" class="cat__head-dots_first"></div>
                            <div id="rightDot" class="cat__head-dots_second"></div>
                        </div>
                        <div class="cat__eye">
                            <div class="cat__eye--left">
                                <span class="pupil-left blinking"></span>
                            </div>
                            <div class="cat__eye--right">
                                <span class="pupil-right blinking"></span>
                            </div>
                        </div>
                        <div class="cat__nose"></div>

                        <div class="cat__mouth-contour"></div>
                        <div class="cat__mouth-left"></div>
                        <div class="cat__mouth-right"></div>

                        <div class="cat__whiskers-left"></div>
                        <div class="cat__whiskers-right"></div>
                    </div>

                    <div id="cat_body" class="cat__body">

                        <div class="cat__chest breathing"></div>

                        <div class="cat__chest_inner breathing"></div>


                        <div class="cat__paw-left"></div>
                        <div class="cat__paw-left_inner"></div>


                        <div class="cat__paw-right"></div>
                        <div class="cat__paw-right_inner"></div>


                        <div id="tail" class="cat__tail"></div>
                    </div>
                </div>
                <br>
                <div class="dnaDiv" id="catDNA">
                    <b>
                        DNA:
                        <!-- Colors -->
                         <span id="dnabody"></span>
                         <span id="dnamouth"></span>
                         <span id="dnaeyes"></span>
                         <span id="dnaears"></span>
                        
                         <!-- Cattributes -->
                         <span id="dnashape"></span>
                         <span id="dnadecoration"></span>
                         <span id="dnadecorationMid"></span>
                         <span id="dnadecorationSides"></span>
                         <span id="dnaanimation"></span>
                         <span id="dnaspecial"></span>
                    </b>
                </div>
            </div>
            <div class="col-lg-7 cattributes m-2 light-b-shadow">

    <div id="rightBox">
        <ul class="nav nav-pills mb-4">
            <li class="nav-item" id="colorsButton">
              <a class="nav-link active" id="colorsLink" aria-current="page" href="#">Colours</a>
            </li>
            <li class="nav-item" id="cattributesButton">
              <a class="nav-link" id="cattributesLink" href="#">Cattributes</a>
            </li>
          </ul>
            
            <!-- Cat colors -->
            <div id="catColors">
                <div class="form-group">
                    <label for="formControlRange"><b>Head and Body Color</b><span class="badge badge-dark ml-2" id="headcode"></span></label>
                    <input type="range" min="10" max="98" class="form-control-range mb-3" id="bodycolor">

                    <label for="formControlRange"><b>Mouth and Tail Color</b><span class="badge badge-dark ml-2" id="mouthtailcode"></span></label>
                    <input type="range" min="10" max="98" class="form-control-range mb-3" id="mouthtailcolor">

                    <label for="formControlRange"><b>Eye Color</b><span class="badge badge-dark ml-2" id="eyecode"></span></label>
                    <input type="range" min="10" max="98" class="form-control-range mb-3" id="eyecolor">

                    <label for="formControlRange"><b>Ear Color</b><span class="badge badge-dark ml-2" id="earcode"></span></label>
                    <input type="range" min="10" max="98" class="form-control-range mb-3" id="earcolor">
                </div>
            </div>
            <div id="cattributes">
                <label for="formControlRange"><b>Eye Shape</b><span class="badge badge-dark ml-2" id="eyename"></span></label>
                <input type="range" min="1" max="6" class="form-control-range mb-3" id="eyeshape">

                <label for="formControlRange"><b>Hair Type</b><span class="badge badge-dark ml-2" id="decorationName"></span></label>
                <input type="range" min="1" max="5" class="form-control-range mb-3" id="decorationpattern">

                <div class="form-control-range">
                    <div class="row">
                        <div class="col-sm">
                            <label for="formControlRange"><b>Primary Hair Color</b><span class="badge badge-dark ml-2" id="haircolorprimaryname"></span></label>
                        </div>
                        <div class="col-sm">
                            <label for="formControlRange"><b>Secondary Hair Color</b><span class="badge badge-dark ml-2" id="haircolorsecondaryname"></span></label>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-sm">
                            <input type="range" min="10" max="98" class="form-control-range mb-3" id="haircolorprimary">
                        </div>
                        <div class="col-sm">
                            <input type="range" min="10" max="98" class="form-control-range mb-3" id="haircolorsecondary">
                        </div>
                    </div>
                </div>

                <label for="formControlRange"><b>Activity</b><span class="badge badge-dark ml-2" id="activityname"></span></label>
                <input type="range" min="1" max="5" class="form-control-range mb-3" id="activity">
            </div>
        <div id="bottomButtons" class="d-flex justify-content-center mt-4">
            <button class="btn btn-dark mr-2" id="generateDefault">Reset Kitty</button>
            <button class="btn btn-warning ml-2 mr-2" id="generateRandomButton">Randomize Kitty</button>
            <button class="btn btn-success ml-2" id="mintCat"><strong>Mint Kitty</strong></button>
        </div>
    </div>

    </div>

</div>
    <br>

</div>



    </div>

  </body>
  <script src="assets/js/colors.js"></script>
  <script src="assets/js/catSettings.js"></script>
  <script src="assets/js/catFactory.js"></script>
  <script src="assets/js/frontendFunctions.js"></script>

</html>

frontendFunctions.js


$(document).ready(() => {
    $('#cattributes').css('display', 'none')
})

$('#generateDefault').click(() => {
    $('#dnabody').html(defaultDNA.headColor);
    $('#dnamouth').html(defaultDNA.mouthColor);
    $('#dnaeyes').html(defaultDNA.eyesColor);
    $('#dnaears').html(defaultDNA.earsColor);
  
    $('#dnashape').html(defaultDNA.eyesShape);
    $('#dnadecoration').html(defaultDNA.decorationPattern);
    $('#dnadecorationMid').html(defaultDNA.decorationMidcolor);
    $('#dnadecorationSides').html(defaultDNA.decorationSidescolor);
    $('#dnaanimation').html(defaultDNA.animation);
    $('#dnaspecial').html(defaultDNA.lastNum);
  
    renderCat(defaultDNA)
})

$('#colorsButton').click(() => {
    $('#cattributesLink').removeClass('active')
    $('#colorsLink').addClass('active')
    $('#cattributes').css('display', 'none')
    $('#catColors').css('display', 'block')
})

$('#cattributesButton').click(() => {
    $('#colorsLink').removeClass('active')
    $('#cattributesLink').addClass('active')
    $('#catColors').css('display', 'none')
    $('#cattributes').css('display', 'block')
})

$('#generateRandomButton').click(() => {
    var randomHeadColor = parseFloat(Math.floor(Math.random() * ($('#bodycolor').prop('max') - $('#bodycolor').prop('min') + 1))) + parseFloat($('#bodycolor').prop('min'))
    $('#bodycolor').val(randomHeadColor)
    headColor(colors[randomHeadColor],randomHeadColor)

    var randomMouthColor = parseFloat(Math.floor(Math.random() * ($('#mouthtailcolor').prop('max') - $('#mouthtailcolor').prop('min') + 1))) + parseFloat($('#mouthtailcolor').prop('min'))
    $('#mouthtailcolor').val(randomMouthColor)
    mouthTailColor(colors[randomMouthColor],randomMouthColor)

    var randomEyeColor = parseFloat(Math.floor(Math.random() * ($('#eyecolor').prop('max') - $('#eyecolor').prop('min') + 1))) + parseFloat($('#eyecolor').prop('min'))
    $('#eyecolor').val(randomEyeColor)
    eyeColor(colors[randomEyeColor], randomEyeColor)

    var randomEarColor = parseFloat(Math.floor(Math.random() * ($('#earcolor').prop('max') - $('#earcolor').prop('min') + 1))) + parseFloat($('#earcolor').prop('min'))
    $('#earcolor').val(randomEarColor)
    earColor(colors[randomEarColor],randomEarColor)

    var randomEyeShape = parseFloat(Math.floor(Math.random() * ($('#eyeshape').prop('max') - $('#eyeshape').prop('min') + 1))) + parseFloat($('#eyeshape').prop('min'))
    $('#eyeshape').val(randomEyeShape)
    eyeVariation(randomEyeShape)

    var randomDecoration = parseFloat(Math.floor(Math.random() * ($('#decorationpattern').prop('max') - $('#decorationpattern').prop('min') + 1))) + parseFloat($('#decorationpattern').prop('min'))
    $('#decorationpattern').val(randomDecoration)
    decorationVariation(randomDecoration)

    var randomHairColorPrimary = parseFloat(Math.floor(Math.random() * ($('#haircolorprimary').prop('max') - $('#haircolorprimary').prop('min') + 1))) + parseFloat($('#haircolorprimary').prop('min'))
    $('#haircolorprimary').val(randomHairColorPrimary)
    hairColorPrimary(colors[randomHairColorPrimary], randomHairColorPrimary)

    var randomHairColorSecondary = parseFloat(Math.floor(Math.random() * ($('#haircolorsecondary').prop('max') - $('#haircolorsecondary').prop('min') + 1))) + parseFloat($('#haircolorsecondary').prop('min'))
    $('#haircolorsecondary').val(randomHairColorSecondary)
    hairColorSecondary(colors[randomHairColorSecondary], randomHairColorSecondary)

    var randomActivity = parseFloat(Math.floor(Math.random() * ($('#activity').prop('max') - $('#activity').prop('min') + 1))) + parseFloat($('#activity').prop('min'))
    console.log(randomActivity)
    $('#activity').val(randomActivity)
    activityVariation(randomActivity)
})

catSettings.js


var colors = Object.values(allColors())

var defaultDNA = {
    "headcolor" : 15,
    "mouthColor" : 23,
    "eyesColor" : 93,
    "earsColor" : 10,
    //Cattributes
    "eyesShape" : 1,
    "decorationPattern" : 1,
    "decorationMidcolor" : 13,
    "decorationSidescolor" : 13,
    "animation" :  1,
    "lastNum" :  1
    }

// when page load
$( document ).ready(function() {
  $('#dnabody').html(defaultDNA.headColor);
  $('#dnamouth').html(defaultDNA.mouthColor);
  $('#dnaeyes').html(defaultDNA.eyesColor);
  $('#dnaears').html(defaultDNA.earsColor);

  $('#dnashape').html(defaultDNA.eyesShape);
  $('#dnadecoration').html(defaultDNA.decorationPattern);
  $('#dnadecorationMid').html(defaultDNA.decorationMidcolor);
  $('#dnadecorationSides').html(defaultDNA.decorationSidescolor);
  $('#dnaanimation').html(defaultDNA.animation);
  $('#dnaspecial').html(defaultDNA.lastNum);

  renderCat(defaultDNA)
});

function getDna(){
    var dna = ''
    dna += $('#dnabody').html()
    dna += $('#dnamouth').html()
    dna += $('#dnaeyes').html()
    dna += $('#dnaears').html()
    dna += $('#dnashape').html()
    dna += $('#dnadecoration').html()
    dna += $('#dnadecorationMid').html()
    dna += $('#dnadecorationSides').html()
    dna += $('#dnaanimation').html()
    dna += $('#dnaspecial').html()

    return parseInt(dna)
}

function renderCat(dna){
    headColor(colors[dna.headcolor],dna.headcolor)
    $('#bodycolor').val(dna.headcolor)

    mouthTailColor(colors[dna.mouthColor], dna.mouthColor)
    $('#mouthtailcolor').val(dna.mouthColor)

    eyeColor(colors[dna.eyesColor], dna.eyesColor)
    $('#eyecolor').val(dna.eyesColor)

    earColor(colors[dna.earsColor], dna.earsColor)
    $('#earscolor').val(dna.earsColor)

    eyeVariation(dna.eyesShape)
    $('#eyeshape').val(dna.eyesShape)

    decorationVariation(dna.decorationPattern)
    $('#decorationpattern').val(dna.decorationPattern)

    hairColorPrimary(colors[dna.decorationMidcolor], dna.decorationMidcolor)
    $('#haircolorprimary').val(dna.decorationMidcolor)

    hairColorSecondary(colors[dna.decorationSidescolor], dna.decorationSidescolor)
    $('#haircolorsecondary').val(dna.decorationSidescolor)

    activityVariation(dna.animation)
    $('#activity').val(dna.animation)
}

// Changing cat colors
$('#bodycolor').change(()=>{
    var colorVal = $('#bodycolor').val()
    headColor(colors[colorVal],colorVal)
})

$('#mouthtailcolor').change(() => {
  var mouthTailColorVal = $('#mouthtailcolor').val()
  mouthTailColor(colors[mouthTailColorVal], mouthTailColorVal)
})

$('#eyecolor').change(() => {
  var eyeColorVal = $('#eyecolor').val()
  eyeColor(colors[eyeColorVal], eyeColorVal)
})

$('#earcolor').change(() => {
  var earColorVal = $('#earcolor').val()
  earColor(colors[earColorVal], earColorVal)
})


// Changing Cattributes

$('#eyeshape').change(() => {
  var eyeShapeVal = parseInt($('#eyeshape').val()) // Between 1 and 7
  eyeVariation(eyeShapeVal)
})

$('#decorationpattern').change(() => {
  var decorationVal = parseInt($('#decorationpattern').val())
  decorationVariation(decorationVal)
})

$('#haircolorprimary').change(() => {
  var hairColorPrimaryVal = $('#haircolorprimary').val()
  hairColorPrimary(colors[hairColorPrimaryVal], hairColorPrimaryVal)
})

$('#haircolorsecondary').change(() => {
  var hairColorSecondaryVal = $('#haircolorsecondary').val()
  hairColorSecondary(colors[hairColorSecondaryVal], hairColorSecondaryVal)
})

$('#activity').change(() => {
  var activityVal = parseInt($('#activity').val())
  activityVariation(activityVal)
})

catFactory.js

//Random color
function getColor() {
    var randomColor = Math.floor(Math.random() * 16777215).toString(16);
    return randomColor
}

function genColors(){
    var colors = []
    for(var i = 10; i < 99; i ++){
      var color = getColor()
      colors[i] = color
    }
    return colors
}

//This function code needs to modified so that it works with Your cat code.
function headColor(color,code) {
    $('.cat__head, .cat__chest').css('background', '#' + color)  //This changes the color of the cat
    $('#headcode').html('code: '+code) //This updates text of the badge next to the slider
    $('#dnabody').html(code) //This updates the body color part of the DNA that is displayed below the cat
}

function mouthTailColor(color, code) {
    $('.cat__mouth-contour, .cat__mouth-left, cat__mouth-right').css('background', '#' + color)
    $('#mouthtailcode').html('code: '+code) // Updates Badge
    $('#dnamouth').html(code) // Updates DNA String
}

function eyeColor(color, code) {
    $('.pupil-left, .pupil-right').css('background', '#' + color)
    $('#eyecode').html('code: ' +code) // Updates Bade
    $('#dnaeyes').html(code) // Updates DNA String
}

function earColor(color, code) {
    $('#leftEar, #rightEar').css('background', '#' + color)
    $('#earcode').html('code: ' + code) // Updates Badge
    $('#dnaears').html(code) // Updates DNA String
}

function hairColorPrimary(color, code) {
    $('#midDot').css('background', '#' + color)
    $('#haircolorprimaryname').html('code: ' + code)
    $('#dnadecorationMid').html(code)
}

function hairColorSecondary(color, code) {
    $('#leftDot, #rightDot').css('background', '#' + color)
    $('#haircolorsecondaryname').html('code: ' + code)
    $('#dnadecorationSides').html(code)
}

//###################################################
//Functions below will be used later on in the project
//###################################################
function eyeVariation(num) {

    $('#dnashape').html(num) // Set DNA String
    switch (num) {
        case 1:
            normalEyes()
            $('#eyename').html('Basic') // Set Badge To 'Basic'
            break
        case 2:
            normalEyes()
            $('#eyename').html('Looking Down') // Set Badge To 'Looking Down'
            eyesType1()
            break
        case 3:
            normalEyes()
            $('#eyename').html('Looking Up') // Set Badge To 'Looking Up'
            eyesType2()
            break
        case 4:
            normalEyes()
            $('#eyename').html('Looking Left') // Set Badge To 'Looking Left'
            eyesType3()
            break
        case 5:
            normalEyes()
            $('#eyename').html('Looking Right') // Set Badge To 'Looking Right'
            eyesType4()
            break
        case 6:
            normalEyes()
            $('#eyename').html('Tiny Eyes') // Set Badge To 'Tiny Eyes'
            eyesType5()
            break
        default:
            normalEyes()
            $('#eyename').html('Error')
            break
    }
}

function decorationVariation(num) {
    $('#dnadecoration').html(num) // Set DNA String
    switch (num) {
        case 1:
            $('#decorationName').html('Basic')
            normaldecoration()
            break
        case 2:
            normaldecoration()
            $('#decorationName').html('Long Hair')
            decorationType1()
            break
        case 3:
            normaldecoration()
            $('#decorationName').html('Messy')
            decorationType2()
            break
        case 4:
            normaldecoration()
            $('#decorationName').html('Spiky')
            decorationType3()
            break
        case 5:
            normaldecoration()
            $('#decorationName').html('Flat')
            decorationType4()
            break
        default:
            normaldecoration()
            $('#decorationName').html('Error')
    }
}

function activityVariation(num) {
    $('#dnaanimation').html(num) // Set DNA String

    switch (num) {
        case 1:
            $('#activityname').html('Cutesy')
            animationType1()
            break
        case 2:
            $('#activityname').html('Boo!')
            animationType2()
            break
        case 3:
            $('#activityname').html('Waving')
            animationType3()
            break
        case 4:
            $('#activityname').html('Vibin')
            animationType4()
            break
        case 5:
            $('#activityname').html('Tail Wag')
            animationType5()
            break
        default:
            $('#activityname').html('Error')
            break
    }
}

// Set Eye Types

async function normalEyes() {
    await $('.cat__eye').find('span').css('border', 'none')
}

async function eyesType1() {
    await normalEyes()
    await $('.cat__eye').find('span').css('border-top', '15px solid')
}

async function eyesType2() {
    await normalEyes()
    await $('.cat__eye').find('span').css('border-bottom', '15px solid')
}

async function eyesType3() {
    await normalEyes()
    await $('.cat__eye').find('span').css('border-right', '15px solid')
}

async function eyesType4() {
    await normalEyes()
    await $('.cat__eye').find('span').css('border-left', '15px solid')
}

async function eyesType5() {
    await normalEyes()
    await $('.cat__eye').find('span').css('border', '15px solid')
}


// Set Hair Decoration

async function normaldecoration() {
    //Remove all style from other decorations
    //In this way we can also use normalDecoration() to reset the decoration style
    $('.cat__head-dots').css({ "transform": "rotate(0deg)", "height": "48px", "width": "14px", "top": "1px", "border-radius": "0 0 50% 50%" })
    $('.cat__head-dots_first').css({ "transform": "rotate(0deg)", "height": "35px", "width": "14px", "top": "1px", "border-radius": "50% 0 50% 50%" })
    $('.cat__head-dots_second').css({ "transform": "rotate(0deg)", "height": "35px", "width": "14px", "top": "1px", "border-radius": "0 50% 50% 50%" })
}

async function decorationType1() {
    await $('#midDot, #leftDot, #rightDot').css('height', '70px')
}

async function decorationType2() {
    await $('#leftDot').css('transform', 'rotate(-45deg)')
    await $('#rightDot').css('transform', 'rotate(45deg)')
}

async function decorationType3() {
    await $('#midDot, #leftDot, #rightDot').css('transform', 'rotate(180deg)')
}

async function decorationType4() {
    await $('#midDot, #leftDot, #rightDot').css('width', '20px')
}


// Set Activity Animation

async function resetanimation() {
    await $('#head, .cat__ear').removeClass('tiltingHead')
    await $('#head, .cat__ear').removeClass('scary')
    await $('.cat__paw-left, .cat__paw-right').removeClass('dancing')
    await $('#head, .cat__ear').removeClass('vibing')
    await $('#tail').removeClass('wagging')
}

async function animationType1() { // Tiltin
    await resetanimation()
    await $('#head, .cat__ear').addClass('tiltingHead')
}

async function animationType2() { // Scarin
    await resetanimation()
    await $('#head, .cat__ear').addClass('scary')
}

async function animationType3() { // Dancin
    await resetanimation()
    await $('.cat__paw-left, .cat__paw-right').addClass('dancing')
}

async function animationType4() { // Vibin
    await resetanimation()
    await $('.cat__paw-left, .cat__paw-right').addClass('dancing')
    await $('#head, .cat__ear').addClass('vibing')
}

async function animationType5() { // Tail Wag
    await resetanimation()
    await $('#tail').addClass('wagging')
}

animations.css

.blinking {
    animation: blinks 3s infinite;
}

@keyframes blinks {
    0%, 29%, 31%, 47%, 49% {
        border-top: 0px;
        border-bottom: 0px;
    }
    30%, 48% {
        border-top: 20px solid;
        border-bottom: 20px solid;
    }
}

.breathing {
    animation: breathe 4s infinite;
}

@keyframes breathe {
    20%, 80% {
        transform: scaleX(100%);
        transform: translateY(0%);
    }
    40%, 55% {
        transform: scaleX(110%);
        transform: translateY(-3px);
    }
}

.scary {
    animation: boo 4s infinite;
}

@keyframes boo {
    0%, 80%, 90% {
        transform: scale(100%);
    }
    81% {
        transform: scale(130%);
    }
}

.tiltingHead {
    animation: headTilt 5s infinite;
}

@keyframes headTilt {
    0%, 30% {
        transform: rotate(0deg);
    }
    10% {
        transform: rotate(-5deg);
    }
    20% {
        transform: rotate(5deg);
    }
}

.dancing {
    bottom: -30px;
    animation: dance 2s infinite;
}

@keyframes dance {
    0%, 60%, 100% {
        transform: rotate(0deg);
    }
    40% {
        transform: rotate(-20deg);
    }
    80% {
        transform: rotate(20deg);
    }
}

.vibing {
    animation: vibe 1s infinite;
}

@keyframes vibe {
    0%, 100% {
        transform: translateY(20px);
    }
    50% {
        transform: translateY(-20px);
    }
}

.wagging {
    animation: wag 1s infinite;
}

@keyframes wag {
    0%, 100% {
        transform: rotate(-15deg);
    }
    50% {
        transform: rotate(15deg);
    }
}
1 Like

Another very good learning experience in this assignment. Thank you Moralis Academy Team.

Relevant code changes in index.html

...
 <!-- Tabs -->
                <ul class="nav nav-tabs" role="tablist">
                    <li class="nav-item" role="presentation">
                      <a class="nav-link active" data-toggle="tab" href="#catColors" role="tab">Colors</a>
                    </li>
                    <li class="nav-item" role="presentation">
                      <a class="nav-link" data-toggle="tab" href="#cattributes" role="tab">Cattributes</a>
                    </li>
                </ul>

                <div class="tab-content">
                    <!-- Cat colors -->
                    <div id="catColors" class="tab-pane fade show active" role="tabpanel">
...
<!-- Cattributes -->
                    <div id="cattributes" class="tab-pane fade show" role="tabpanel">
...
                <!-- Cat Buttons -->
                <div class="buttons m-3">
                    <button class="btn btn-light" onclick="randomCat()">Random Kitty</button>
                    <button class="btn btn-light" onclick="defaultCat()">Default Kitty</button>
                    <button class="btn btn-light" onclick="newCat()">New Kitty</button>
                </div>
...

For the changes in catSettings.js

...
// Cat Buttons
function randomCat() {

  let randomDNA = {
    "headcolor" : Math.floor(Math.random() * 89) + 10,
    "tailColor" : Math.floor(Math.random() * 89) + 10,
    "pawColor" : Math.floor(Math.random() * 89) + 10,
    "eyecolor" : Math.floor(Math.random() * 89) + 10,
    "whiskerColor" : Math.floor(Math.random() * 89) + 10,
    "noseColor" : Math.floor(Math.random() * 89) + 10,
    "mouthColor" : Math.floor(Math.random() * 89) + 10,
    //Cattributes
    "eyesShape" : Math.floor(Math.random() * 4) + 1,
    "decorationPattern" : Math.floor(Math.random() * 4) + 1,
    "decorationMidcolor" : Math.floor(Math.random() * 89) + 10,
    "decorationSidescolor" : Math.floor(Math.random() * 89) + 10,
    "animation" :  Math.floor(Math.random() * 4) + 1,
    "lastNum" :  1
    }

    renderCat(randomDNA);
}

function defaultCat() {
  $('#dnabody').html(defaultDNA.headColor);
  $('#dnatail').html(defaultDNA.tailColor);
  $('#dnapaw').html(defaultDNA.pawColor);
  $('#dnaeyes').html(defaultDNA.eyecolor);
  $('#dnawhisker').html(defaultDNA.whiskerColor);
  $('#dnanose').html(defaultDNA.noseColor);
  $('#dnamouth').html(defaultDNA.mouthColor);
    
  $('#dnashape').html(defaultDNA.eyesShape);
  $('#dnadecoration').html(defaultDNA.decorationPattern);
  $('#dnadecorationMid').html(defaultDNA.decorationMidcolor);
  $('#dnadecorationSides').html(defaultDNA.decorationSidescolor);
  $('#dnaanimation').html(defaultDNA.animation);

  $('#dnaspecial').html(defaultDNA.lastNum);

  renderCat(defaultDNA); 
}

function newCat() {
  console.log('newCat');
}
...
2 Likes

Thank you, your renderCat(randomDNA) did help me!!!

1 Like

I set the tabs at the upper portion of the DNA selection box, and set the 3 buttons as static buttons for both tabs.

Default Fish

Random Fish

index.html
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Academy fishies </title>
  <script type="text/javascript" src="assets/js/jquery-3.4.1.js"></script>
  <link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
  <script src="assets/bootstrap/js/popper.js"></script>
  <script src="assets/bootstrap/js/bootstrap.min.js"></script>

  <link rel="stylesheet" href="assets/css/mystyle.css">
  <link rel="stylesheet" href="assets/css/cats.css">
  <link rel="stylesheet" href="assets/css/colors.css">
  <link rel="stylesheet" href="assets/css/factory.css">
  <link rel="stylesheet" href="assets/css/frontend.css">
  <link rel="stylesheet" href="assets/css/animations.css">
</head>
  <body>
    <div class="container p-5" style="margin-top: 12vh;margin-bottom: 10vh;">
        <div align="center">
        <h1 class="c-white">Fishies-Factory</h1>
        <p class="c-white">Create your custom Fishy</p>
        </div>
        <div class="row">
            <div class="col-lg-4 catBox m-2 light-b-shadow">
                <div class="fish">
                    <div class="fins" id=fins>
                        <div id="leftFin" class="fish__fin--left">
                            <div id="leftShade" class="fish__fin-leftShade"></div>
                        </div>
                        <div id="rightFin" class="fish__fin--right">
                            <div id="rightShade" class="fish__fin-rightShade"></div>
                        </div>
                        <div id="topFin" class="fish__tailFin--top">
                            <div id="topTailShade" class="fish__tailFin-topShade"></div>
                        </div>
                        <div id="bottomFin" class="fish__tailFin--bottom">
                            <div id="bottomTailShade" class="fish__tailFin-bottomShade"></div>
                        </div>
                        <div id="dorsalFin" class="fish__stableFin--dorsal"></div>
                        <div id="st_leftFin" class="fish__stableFin--left"></div>
                        <div id="st_rightFin" class="fish__stableFin--right"></div>
                    </div>

                    <div id="body" class="fish__body">
                        <div class="fish__eye">
                            <span class="fish__eye--left">
                                <div class="pupil-left"></div>
                            </span>
                            <span class="fish__eye--right">
                                <div class="pupil-right"></div>
                            </span>
                        </div>
                        <div id="mouth" class="fish__mouth">
                            <div id="teeth" class="fish__mouth-teeth"></div>
                        </div>
                    </div>
                </div>
                <br>
                <div class="dnaDiv" id="catDNA">
                    <b>
                        DNA:
                        <!-- Colors -->
                         <span id="dnabody"></span>
                         <span id="dnaside"></span>
                         <span id="dnatail"></span>
                         <span id="dnastablizer"></span>
                         <span id="dnaeye"></span>
                        
                         <!-- Cattributes -->
                         <span id="dnashape"></span>
                         <span id="dnadecoration"></span>
                         <span id="dnadecorationMid"></span>
                         <span id="dnadecorationSides"></span>
                         <span id="dnaanimation"></span>
                         <span id="dnaspecial"></span>
                    </b>
                </div>
            </div>
                        <!-- Fish colors/attributes -->
            <div class="col-lg-7 cattributes m-2 light-b-shadow">
                <div class="tabs">
                    <div class="tabs__sidebar">
                        <button class="tabs__button" data-for-tab="1">Fishy Colors</button>
                        <button class="tabs__button" data-for-tab="2">Fishy Attributes</button>
                    </div>
                    <br>
                    <div class="static__buttons">
                        <button class="button__static" id="button_defaultFish" onclick="renderFish(defaultDNA);">Default Fishy</button>
                        <button class="button__static" id="button_randomFish" onclick="renderRandomFish();">Random Fishy</button>
                        <button class="button__static" id="button_newFish">Create New Fishy</button>
                    </div>
                    <br><br>
                    <div class="tabs__content" data-tab="1">
                        <div id="catColors">
                            <div class="form-group">
                                <label for="formControlRange"><b>Head and body</b><span class="badge badge-dark ml-2" id="headcode"></span></label>
                                <input type="range" min="10" max="98" class="form-control-range" id="bodycolor">
                            </div>
                            <div class="form-group">
                                <label for="formControlRange"><b>Side Fins</b><span class="badge badge-dark ml-2" id="sideFinCode"></span></label>
                                <input type="range" min="10" max="98" class="form-control-range" id="sideFinColor">
                            </div>
                            <div class="form-group">
                                <label for="formControlRange"><b>Tail Fins</b><span class="badge badge-dark ml-2" id="tailcode"></span></label>
                                <input type="range" min="10" max="98" class="form-control-range" id="tailFinColor">
                            </div>
                            <div class="form-group">
                                <label for="formControlRange"><b>Stabilizer Fins</b><span class="badge badge-dark ml-2" id="stablizercode"></span></label>
                                <input type="range" min="10" max="98" class="form-control-range" id="stableFinColor">
                            </div>
                            <div class="form-group">
                                <label for="formControlRange"><b>Eyes</b><span class="badge badge-dark ml-2" id="eyecode"></span></label>
                                <input type="range" min="10" max="98" class="form-control-range" id="eyeColor">
                            </div>
                        </div>
                    </div>
                    <div class="tabs__content" data-tab="2">
                        <div id="fishAttributes">
                            <div class="form-group">
                                <label for="formControlRange"><b>Eye Shape</b><span class="badge badge-dark ml-2" id="eyeName"></span></label>
                                <input type="range" min="1" max="4" class="form-control-range" id="eyesShape">
                            </div>
                            <div class="form-group">
                                <label for="formControlRange"><b>Fin Decoration</b><span class="badge badge-dark ml-2" id="finDecorationName"></span></label>
                                <input type="range" min="1" max="4" class="form-control-range" id="finDecoration">
                            </div>
                            <div class="form-group">
                                <label for="formControlRange"><b>Side Fin Shade Colors</b><span class="badge badge-dark ml-2" id="sideShadeCode"></span></label>
                                <input type="range" min="10" max="98" class="form-control-range" id="sideShadeColor">
                            </div>
                            <div class="form-group">
                                <label for="formControlRange"><b>Tail Fin Shade Colors</b><span class="badge badge-dark ml-2" id="tailShadeCode"></span></label>
                                <input type="range" min="10" max="98" class="form-control-range" id="tailShadeColor">
                            </div>
                            <div class="form-group">
                                <label for="formControlRange"><b>Animation</b><span class="badge badge-dark ml-2" id="animationCode"></span></label>
                                <input type="range" min="1" max="4" class="form-control-range" id="animations">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <br>
    </div>

    <footer align="left">
        <p>Ivan on Tech Academy Bootcamp July 2020</p>
    </footer>

  </body>
  <script src="assets/js/colors.js"></script>
  <script src="assets/js/catSettings.js"></script>
  <script src="assets/js/catFactory.js"></script>

</html>
factory.css
.catBox {
    background-color: #e2efff;
    border-radius: 10px;
    padding-top: 50px;
    padding-left: 65px;
    padding-bottom: 100px;
}

.cattributes {
    padding: 25px;
    background-color: #ededed;
    border-radius: 10px;
}

.dnaDiv {
    position: absolute;
    left:20px;
    bottom: 5px;
 
}

/* EXTRA TABS LOGIC */
.tabs {
    border: 1px solid rgb(255, 255, 255);
}

.tabs__sidebar {
    flex-shrink: 0;
    background: #ccc;
}

.tabs__button {
    padding-right: 20px;
    padding-left: 20px;
    background: #eee;
    border-bottom: none;
    outline: none;
    cursor: pointer;
    width: max-content;
}

.tabs__button:active {
    background: #dddd;
}

/*may not need this since I'm putting tabs at the top instead of the side*/
.tabs__button:not(:last-of-type) {
    border-bottom: 1px solid #ccc;
}

.tabs__button--active {
    font-weight: bold;
    border-right: 2px solid #009879;
    background: #ddd;
}

.tabs__content {
    padding: 15px;
    font-size: 0.8rem;
    display: none;
}

.tabs__content--active {
    display: contents;
}

/*remove any potential extra spacing between the top of the content and the bottom of the tabs*/
.tabs__content > :first-child {
    margin-top: 0;
}

.button__static {
    padding-right: 10px;
    padding-left: 10px;
}
catFactory.js

//Random color
function getColor() {
    var randomColor = Math.floor(Math.random() * 16777215).toString(16);
    return randomColor
}

function genColors(){
    var colors = []
    for(var i = 10; i < 99; i ++){
      var color = getColor()
      colors[i] = color
    }
    return colors
}

//This function code needs to modified so that it works with Your cat/fish code.
function headColor(color,code) {
    $('.fish__body').css('background', '#' + color)  //This changes the color of the fish head/body
    $('#headcode').html('code: '+code) //This updates text of the badge next to the slider
    $('#dnabody').html(code) //This updates the body color part of the DNA that is displayed below the fish
}

//Side Fin color function
function sideFinColor(color,code) {
    $('.fish__fin--left, .fish__fin--right').css('background', '#' + color)
    $('#sideFinCode').html('code: '+code)
    $('#dnaside').html(code)
}

//Tail Fin color function
function tailFinColor(color,code) {
    $('.fish__tailFin--top, .fish__tailFin--bottom').css('background', '#' + color)
    $('#tailcode').html('code: '+code)
    $('#dnatail').html(code)
}

//Stabilizer Fin color function
function stableFinColor(color,code) {
    $('.fish__stableFin--dorsal, .fish__stableFin--left, .fish__stableFin--right').css('background', '#' + color)  
    $('#stablizercode').html('code: '+code)
    $('#dnastablizer').html(code)
}

//Eye color function
function eyeColor(color,code) {
    $('.fish__eye--left, .fish__eye--right').css('background', '#' + color) 
    $('#eyecode').html('code: '+code)
    $('#dnaeye').html(code)
}

//Side Shade Fin color function
function sideShadeColor(color,code) {
    $('.fish__fin-leftShade, .fish__fin-rightShade').css('background', '#' + color)
    $('#sideShadeCode').html('code: '+code)
    $('#dnadecorationSides').html(code)
}

//Tail Shade Fin color function
function tailShadeColor(color,code) {
    $('.fish__tailFin-topShade, .fish__tailFin-bottomShade').css('background', '#' + color)  //This changes the color of the tailfin
    $('#tailShadeCode').html('code: '+code) //This updates text of the badge next to the slider
    $('#dnadecorationMid').html(code) //This updates the tail fin color part of the DNA that is displayed below the fish
}


//###################################################
//Functions below will be used later on in the project
//###################################################
function eyeVariation(num) {
    $('#dnashape').html(num)
    switch (num) {
        case 1:
            normalEyes()
            $('#eyeName').html('Basic') //Set the badge to "Basic"
            break
        case 2:
            normalEyes() //reset
            $('#eyeName').html('Chill') //Set the badge to "Chill"
            eyesType1() //Set border to change the shape of the eyes
            break
        case 3:
            normalEyes() //reset
            $('#eyeName').html('Excited') //Set the badge to "Excite"
            eyesType2() //Set border to change the shape of the eyes
            break
        case 4:
            normalEyes() //reset
            $('#eyeName').html('Shark!!!') //Set the badge to "Shark!!!"
            eyesType3() //Set border to change the shape of the eyes
            break
        default:
            console.log("Not 1 - 4")
            break
    }
}


function decorationVariation(num) {
    $('#dnadecoration').html(num)
    switch (num) {
        case 1:
            $('#finDecorationName').html('Standard')
            normaldecoration()
            break
        case 2:
            normaldecoration() //reset
            $('#finDecorationName').html('Floating')
            decorationType1()
            break
        case 3:
            normaldecoration() //reset
            $('#finDecorationName').html('Half Cut')
            decorationType2()
            break
        case 4:
            normaldecoration() //reset
            $('#finDecorationName').html('No Decoration')
            decorationType3()
            break
        default:
            console.log("Not 1 - 4")
            break
    }
}


function animationVariation(num) {
    $('#dnaanimation').html(num)
    switch (num) {
        case 1:
            $('#animationCode').html('No Animation')
            noAnimation()
            break
        case 2:
            noAnimation() //reset
            $('#animationCode').html('Curious')
            animationType1()
            break
        case 3:
            noAnimation() //reset
            $('#animationCode').html('Swimming')
            animationType2()
            break
        case 4:
            noAnimation() //reset
            $('#animationCode').html('Mouthy')
            animationType3()
            break
        default:
            console.log("Not 1 - 4")
            break
    }
}


function noAnimation() {
    $("#body").removeClass("movingBody");
    $("#fins").removeClass("movingFins");
    $("#rightFin").removeClass("movingFinRight");
    $("#leftFin").removeClass("movingFinLeft");
    $("#topFin").removeClass("movingFinTail");
    $("#bottomFin").removeClass("movingFinTail");
    $("#topTailShade").removeClass("movingFinShadowTail");
    $("#bottomTailShade").removeClass("movingFinShadowTail");
    $("#mouth").removeClass("movingMouth");

}

function animationType1() {//Curious
    $("#body").addClass("movingBody");
}

function animationType2() {//Swimming
    $("#rightFin").addClass("movingFinRight");
    $("#leftFin").addClass("movingFinLeft");
    $("#topFin").addClass("movingFinTail");
    $("#bottomFin").addClass("movingFinTail");
    $("#topTailShade").addClass("movingFinShadowTail");
    $("#bottomTailShade").addClass("movingFinShadowTail");
}

function animationType3() {//Mouthy
    $("#mouth").addClass("movingMouth");
}

async function normalEyes() {
    await $('.fish__eye').find('span').css('border', 'none')
}

async function eyesType1() {//Chill
    await $('.fish__eye').find('span').css('border-top', '15px solid')
}

async function eyesType2() {//Excited
    await $('.fish__eye').find('span').css('border-bottom', '15px solid')
}

async function eyesType3() {//Shark!!!
    await $('.fish__eye').find('span').css('border-left', '15px solid')
}

async function normaldecoration() { //STANDARD
    //Remove all style from other decorations
    //In this way we can also use normalDecoration() to reset the decoration style
    $('.fish__fin-leftShade').css({ "border-radius": "50px 10px 50px 10px", "height": "55px", "width": "50px", "border": "2px solid",
                                    "transform": "scale(1,-1) rotate(60deg)", "left": "30px", "top": "-3px" })
    $('.fish__fin-rightShade').css({ "border-radius": "50px 10px 50px 10px", "height": "55px", "width": "50px", "border": "2px solid",
                                      "transform": "rotate(25deg)", "left": "15px", "top": "0.5px" })
    $('.fish__tailFin-topShade').css({ "border-radius": "75px 150px 35px 90px", "height": "105px", "width": "30px", "border": "2px solid",
                                       "left": "40px", "top": "25px", "transform": "rotate(-25deg)" })
    $('.fish__tailFin-bottomShade').css({ "border-radius": "75px 150px 35px 90px", "height": "105px", "width": "30px", "border": "2px solid",
                                      "left": "40px", "top": "25px", "transform": "rotate(-30deg)" })
}

function decorationType1() { //FLOATING
    $('.fish__fin-leftShade').css({ "border-radius": "50px 10px 50px 10px", "height": "55px", "width": "30px", "border": "2px solid",
                                    "transform": "scale(1,-1) rotate(90deg)", "left": "30px" })
    $('.fish__fin-rightShade').css({ "border-radius": "50px 10px 50px 10px", "height": "55px", "width": "30px", "border": "2px solid",
                                      "transform": "rotate(270deg) scale(-1,1)", "left": "35px", "top": "0.5px" })
    $('.fish__tailFin-topShade').css({ "border-radius": "75px 150px 95px 90px", "height": "55px", "width": "30px", "border": "2px solid",
                                       "left": "25px", "top": "25px", "transform": "rotate(-25deg)" })
    $('.fish__tailFin-bottomShade').css({ "border-radius": "75px 150px 95px 90px", "height": "55px", "width": "30px", "border": "2px solid",
                                      "left": "25px", "top": "25px", "transform": "rotate(-35deg)" })
}

async function decorationType2() { //HALF-CUT
    $('.fish__fin-leftShade').css({ "border-radius": "50px 10px 50px 10px", "height": "55px", "width": "30px", "border": "2px solid",
                                    "transform": "scale(1,-1) rotate(90deg)", "left": "70px", "top": "-10px" })
    $('.fish__fin-rightShade').css({ "border-radius": "50px 10px 50px 10px", "height": "55px", "width": "30px", "border": "2px solid",
                                      "transform": "rotate(55deg)", "left": "-5px", "top": "12px" })
    $('.fish__tailFin-topShade').css({ "border-radius": "75px 150px 35px 90px", "height": "105px", "width": "30px", "border": "2px solid",
                                       "left": "50px", "top": "55px", "transform": "rotate(-25deg)" })
    $('.fish__tailFin-bottomShade').css({ "border-radius": "75px 150px 35px 90px", "height": "105px", "width": "30px", "border": "2px solid",
                                      "left": "50px", "top": "55px", "transform": "rotate(-30deg)" })
}


async function decorationType3() { //NO DECORATION
    $('.fish__fin-leftShade').css({ "display": "none" })
    $('.fish__fin-rightShade').css({ "display": "none" })
    $('.fish__tailFin-topShade').css({ "display": "none" })
    $('.fish__tailFin-bottomShade').css({ "display": "none" })
}


function randomNumberButton(min,max) {
//Pass in the min/max value
    //randomVal = Math.floor(math.random() *89) + 10;
    do {
        randomVal = Math.floor((Math.random() * max) + min);
    }
    while(randomVal > max || randomVal < min);
    return randomVal;
}


function setupTabs () {
    document.querySelectorAll(".tabs__button").forEach(button => {
      button.addEventListener("click", () => {
        //Identify all 4 needed elements
        const sideBar = button.parentElement;
        const tabsContainer = sideBar.parentElement;
        const tabNumber = button.dataset.forTab;
        const tabToActivate = tabsContainer.querySelector(`.tabs__content[data-tab="${tabNumber}"]`);

        console.log(sideBar);
        console.log(tabsContainer);
        console.log(tabNumber);
        console.log(tabToActivate);

        //By default, set the tabs and content to an inactive state
        sideBar.querySelectorAll(".tabs__button").forEach(button => {
            button.classList.remove("tabs__button--active");
        });

        tabsContainer.querySelectorAll(".tabs__content").forEach(tab => {
            tab.classList.remove("tabs__content--active");
            console.log("Should be removing the previous content...");
        });

        //Activate the target
        button.classList.add("tabs__button--active");
        tabToActivate.classList.add("tabs__content--active");

      });
    });
}



catSettings.js

var colors = Object.values(allColors())

var defaultDNA = {
    "bodycolor" : 45,
    "sideFinColor" : 73,
    "tailFinColor" : 96,
    "stableFinColor" : 17,
    "eyeColor" : 32,
    //Cattributes
    "eyesShape" : 1,
    "finDecoration" : 1,
    "tailShadeColor" : 13,
    "sideShadeColor" : 52,
    "animations" :  1,
    "lastNum" :  1
    }

// when page load
$( document ).ready(function() {
  $('#dnabody').html(defaultDNA.bodycolor);
  $('#dnaside').html(defaultDNA.sideFinColor);
  $('#dnatail').html(defaultDNA.tailFinColor);
  $('#dnastablizer').html(defaultDNA.stableFinColor);
  $('#dnaeye').html(defaultDNA.eyeColor);
    
  $('#dnashape').html(defaultDNA.eyesShape);
  $('#dnadecoration').html(defaultDNA.finDecoration);
  $('#dnadecorationMid').html(defaultDNA.tailShadeColor);
  $('#dnadecorationSides').html(defaultDNA.sideShadeColor);
  $('#dnaanimation').html(defaultDNA.animations);
  $('#dnaspecial').html(defaultDNA.lastNum);

  renderFish(defaultDNA);
});

function getDna(){
    var dna = ''
    dna += $('#dnabody').html()
    dna += $('#dnaside').html()
    dna += $('#dnatail').html()
    dna += $('#dnastablizer').html()
    dna += $('#dnaeye').html()

    dna += $('#dnashape').html()
    dna += $('#dnadecoration').html()
    dna += $('#dnadecorationMid').html()
    dna += $('#dnadecorationSides').html()
    dna += $('#dnaanimation').html()
    dna += $('#dnaspecial').html()

    return parseInt(dna)
}

function renderFish(dna){
  //catFactory.js_function (colors[dna.defaultDNA_value],dna.defaultDNA_value)
  //$('#index.html_input_id').val(dna.defaultDNA_value)
    headColor(colors[dna.bodycolor],dna.bodycolor)
    $('#bodycolor').val(dna.bodycolor)
    sideFinColor(colors[dna.sideFinColor],dna.sideFinColor)
    $('#sideFinColor').val(dna.sideFinColor)
    tailFinColor(colors[dna.tailFinColor],dna.tailFinColor)
    $('#tailFinColor').val(dna.tailFinColor)
    stableFinColor(colors[dna.stableFinColor],dna.stableFinColor)
    $('#stableFinColor').val(dna.stableFinColor)
    eyeColor(colors[dna.eyeColor],dna.eyeColor)
    $('#eyeColor').val(dna.eyeColor)

    eyeVariation(dna.eyesShape)
    $('#eyesShape').val(dna.eyesShape)
    decorationVariation(dna.finDecoration)
    $('#finDecoration').val(dna.finDecoration)
    sideShadeColor(colors[dna.sideShadeColor],dna.sideShadeColor)
    $('#sideShadeColor').val(dna.sideShadeColor)
    tailShadeColor(colors[dna.tailShadeColor],dna.tailShadeColor)
    $('#tailShadeColor').val(dna.tailShadeColor)
    animationVariation(dna.animations)
    $('#animations').val(dna.animations)
}

// Changing fish colors
$('#bodycolor').change(()=>{
    var colorVal = $('#bodycolor').val()
    headColor(colors[colorVal],colorVal)
})

// Changing fish colors, side fins
$('#sideFinColor').change(()=>{
  var colorVal = $('#sideFinColor').val()
  sideFinColor(colors[colorVal],colorVal)
})

// Changing fish colors, tail fins
$('#tailFinColor').change(()=>{
  var colorVal = $('#tailFinColor').val()
  tailFinColor(colors[colorVal],colorVal)
})

// Changing fish colors, stabilizer fins
$('#stableFinColor').change(()=>{
  var colorVal = $('#stableFinColor').val()
  stableFinColor(colors[colorVal],colorVal)
})

// Changing fish colors, eyes
$('#eyeColor').change(()=>{
  var colorVal = $('#eyeColor').val()
  eyeColor(colors[colorVal],colorVal)
})

// Changing fish shape, eyes
$('#eyesShape').change(()=>{
  var shape = parseInt($('#eyesShape').val())
  eyeVariation(shape)
})

// Changing fish decoration, tail + fins
$('#finDecoration').change(()=>{
  var style = parseInt($('#finDecoration').val())
  decorationVariation(style)
})

// Changing fish colors, side shade fins
$('#sideShadeColor').change(()=>{
  var colorVal = $('#sideShadeColor').val()
  sideShadeColor(colors[colorVal],colorVal)
})

// Changing fish colors, tail shade fins
$('#tailShadeColor').change(()=>{
  var colorVal = $('#tailShadeColor').val()
  tailShadeColor(colors[colorVal],colorVal)
})

// Changing fish animation
$('#animations').change(()=>{
  var animate = parseInt($('#animations').val())
  animationVariation(animate)
})


//TAB FUNCTIONALITY
document.addEventListener("DOMContentLoaded", () => {
  setupTabs();
  /*Load Tab 1 by default*/
  document.querySelectorAll(".tabs").forEach(tabsContainer => {
    tabsContainer.querySelector(".tabs__sidebar .tabs__button").click();
  });
});


//RANDOM FISH BUTTON
function renderRandomFish() {
  //Set array for randomDNA
  var randomDNA = {
    "bodycolor" : 0,
    "sideFinColor" : 0,
    "tailFinColor" : 0,
    "stableFinColor" : 0,
    "eyeColor" : 0,
    //Fishttributes
    "eyesShape" : 0,
    "finDecoration" : 0,
    "tailShadeColor" : 0,
    "sideShadeColor" : 0,
    "animations" :  0,
    "lastNum" :  1
    }
    console.log(randomDNA, Object.keys(randomDNA)[1], randomDNA.bodycolor, randomDNA.lastNum, Object.values(randomDNA)[1]);
            //  fullset  ,      "sideFinColor"      ,          0         ,         1        ,             0

    /*grab array count*/
    var dnaSize =  Object.keys(randomDNA).length;
    console.log(dnaSize);
    
    /* SKIPPING THIS -- WILL MAKE INDIVIDUAL CALLS BY ID DURING RANDOMDNA ITERATION 
    document.querySelectorAll(".form-control-range").forEach(input => {});
    */

    //for each id, run randomNumberButton function with min/max input, get dna output
    for(let i=0; i < dnaSize; i++) {
      //check id/value
      const sectionDNAValue = Object.values(randomDNA)[i];
      const sectionDNAKey= Object.keys(randomDNA)[i];
      console.log("dnaSize iteration check 1: " + i, sectionDNAValue, sectionDNAKey);

      if (sectionDNAValue < 1) {
        //check min/max
        const htmlKey = document.querySelector(`#${sectionDNAKey}`)
        const rangeMin = htmlKey.min;
        const rangeMax = htmlKey.max;
        let randomNum = 0;

        console.log("dnaSize iteration check 2: " + i, rangeMin, rangeMax);
        //set the random dna number
        randomNum = randomNumberButton(rangeMin,rangeMax);
        console.log("the randomNum is: " + randomNum);
        randomDNA[sectionDNAKey] = randomNum;
      }
      console.log("dnaSize iteration check 3: " + i, "newValue: " + Object.values(randomDNA)[i]);
    }
    
    //match id to array slot and update the value
    $('#dnabody').html(randomDNA.bodycolor);
    $('#dnaside').html(randomDNA.sideFinColor);
    $('#dnatail').html(randomDNA.tailFinColor);
    $('#dnastablizer').html(randomDNA.stableFinColor);
    $('#dnaeye').html(randomDNA.eyeColor);
      
    $('#dnashape').html(randomDNA.eyesShape);
    $('#dnadecoration').html(randomDNA.finDecoration);
    $('#dnadecorationMid').html(randomDNA.sideShadeColor);
    $('#dnadecorationSides').html(randomDNA.tailShadeColor);
    $('#dnaanimation').html(randomDNA.animations);
    $('#dnaspecial').html(randomDNA.lastNum);

    console.log(randomDNA);

    renderFish(randomDNA);
}


Here is my code for this assignment. For whatever reason - the head decoration colors will not go back to their default color setting. I believe my code is correct as the console is not putting any errors out or anything, please correct me if I’m wrong!

index.html:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Academy kitties </title>
  <script type="text/javascript" src="assets/js/jquery-3.4.1.js"></script>
  <link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
  <script src="assets/bootstrap/js/popper.js"></script>
  <script src="assets/bootstrap/js/bootstrap.min.js"></script>

  <link rel="stylesheet" href="assets/css/mystyle.css">
  <link rel="stylesheet" href="assets/css/cats.css">
  <link rel="stylesheet" href="assets/css/colors.css">
  <link rel="stylesheet" href="assets/css/factory.css">
  <link rel="stylesheet" href="assets/css/frontend.css">
  <link rel="stylesheet" href="assets/css/animations.css">
</head>
  <body>
    <div class="container p-5" style="margin-top: 12vh;margin-bottom: 10vh;">
        <div align="center">
        <h1 class="c-white">Kitties-Factory</h1>
        <p class="c-white">Create your custom Kitty</p>
    </div>
        <div class="row">
            <div class="col-lg-4 catBox m-2 light-b-shadow">
                <div class="cat">
                    <div class="cat__ear">
                        <div id="leftEar" class="cat__ear--left">
                            <div class="cat__ear--left-inside"></div>
                        </div>
                        <div id="rightEar" class="cat__ear--right">
                            <div class="cat__ear--right-inside"></div>
                        </div>
                    </div>

                    <div id="head" class="cat__head">
                        <div id="midDot" class="cat__head-dots">
                            <div id="leftDot" class="cat__head-dots_first"></div>
                            <div id="rightDot" class="cat__head-dots_second"></div>
                        </div>
                        <div class="cat__eye">
                            <div class="cat__eye--left">
                                <span class="pupil-left"></span>
                            </div>
                            <div class="cat__eye--right">
                                <span class="pupil-right"></span>
                            </div>
                        </div>
                        <div class="cat__nose"></div>

                        <div class="cat__mouth-contour"></div>
                        <div class="cat__mouth-left"></div>
                        <div class="cat__mouth-right"></div>

                        <div class="cat__whiskers-left"></div>
                        <div class="cat__whiskers-right"></div>
                    </div>

                    <div class="cat__body">

                        <div class="cat__chest"></div>

                        <div class="cat__chest_inner"></div>


                        <div class="cat__paw-left"></div>
                        <div class="cat__paw-left_inner"></div>


                        <div class="cat__paw-right"></div>
                        <div class="cat__paw-right_inner"></div>


                        <div id="tail" class="cat__tail"></div>
                    </div>
                </div>
                <br>
                <div class="dnaDiv" id="catDNA">
                    <b>
                        DNA:
                        <!-- Colors -->
                         <span id="dnabody"></span>
                         <span id="dnamouth"></span>
                         <span id="dnaeyes"></span>
                         <span id="dnaears"></span>
                        
                         <!-- Cattributes -->
                         <span id="dnashape"></span>
                         <span id="dnadecoration"></span>
                         <span id="dnadecorationMid"></span>
                         <span id="dnadecorationSides"></span>
                         <span id="dnadanimation"></span>
                         <span id="dnaspecial"></span>
                    </b>
                </div>
            </div>
            <div class="col-lg-7 cattributes m-2 light-b-shadow">
                <ul class="nav nav-tabs">
                    <li class="nav-item">
                        <a class="nav-link active" id="catColors-tab" data-toggle="tab" href="#catColors" role="tab" aria-controls="catColors" aria-selected="true">Cat Colors</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" id="catAttributes-tab" data-toggle="tab" href="#catAttributes" role="tab" aria-controls="catAttributes" aria-selected="false">Cat Attributes</a>
                    </li>
                </ul>
<!-- Cat colors -->
    <!--Tabs-->
    <div class="tab-content" id="myTabContent">
        <div class="tab-pane fade show active" id="catColors" role="tabpanel" aria-labelledby="catColors-tab"><div class="form-group">
            <label for="formControlRange"><b>Head and Body</b><span class="badge badge-dark ml-2" id="headcode"></span></label>
            <input type="range" min="10" max="98" class="form-control-range" id="bodycolor">
        </div>
        <div class="form-group">
            <label for="formControlRange"><b>Mouth and Tail</b><span class="badge badge-dark ml-2" id="mouthcode"></span></label>
            <input type="range" min="10" max="98" class="form-control-range" id="mouthcolor">
        </div>
        <div class="form-group">
            <label for="formControlRange"><b>Eyes</b><span class="badge badge-dark ml-2" id="eyescode"></span></label>
            <input type="range" min="10" max="98" class="form-control-range" id="eyescolor">
        </div>
        <div class="form-group">
            <label for="formControlRange"><b>Ears and Paws</b><span class="badge badge-dark ml-2" id="earscode"></span></label>
            <input type="range" min="10" max="98" class="form-control-range" id="earscolor">
        </div>
    </div>
        <div class="tab-pane fade" id="catAttributes" role="tabpanel" aria-labelledby="catAttributes-tab"><div class="form-group">
            <label for="formControlRange"><b>Eyes Shape</b><span class="badge badge-dark ml-2" id="eyeName"></span></label>
            <input type="range" min="1" max="7" class="form-control-range" id="eyeshape">
        </div>
        <div class="form-group">
            <label for="formControlRange"><b>Head Decoration</b><span class="badge badge-dark ml-2" id="decorationName"></span></label>
            <input type="range" min="1" max="5" class="form-control-range" id="decorationpattern">
        </div>
        <div class="form-group">
            <label for = "formControlRange"><b>Decoration Color</b></label>
        </div>
        <div class="col">
            <label for="formControlRange"><b>Middle Color</b><span class="badge badge-dark ml-2" id="decorationMid"></span></label>
            <input type="range" min="1" max="98" class="form-control-range" id="decorationmid">
        </div>
        <div class="col">
            <label for="formControlRange"><b>Sides Color</b><span class="badge badge-dark ml-2" id="decorationSides"></span></label>
            <input type="range" min="1" max="98" class="form-control-range" id="decorationsides">
        </div>
        <div class="form-group">
            <label for="formControlRange"><b>Animation</b><span class="badge badge-dark ml-2" id="animationName"></span></label>
            <input type="range" min="1" max="6" class="form-control-range" id="animation">
        </div>
    </div>
    </div>

<!--Cat Attributes-->
    <!--Tabs-->
                
            </div>
            </div>
                <button id="randomCat" class="btn btn-light">Create A Random Cat</button>
                <button id="defaultCat" class="btn btn-light">Get Default Cat</button>
                <button id="createNewCat" class="btn btn-light">Create A New Cat</button>
            </div>
            <br>

        </div>



    </div>
    <footer align="left">
        <p>Ivan on Tech Academy Kitties Clone</p>
    </footer>
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
  </body>

  <script src="assets/js/colors.js"></script>
  <script src="assets/js/catSettings.js"></script>
  <script src="assets/js/catFactory.js"></script>

</html>

catSettings.js:


var colors = Object.values(allColors())

var defaultDNA = {
    "headColor" : 10,
    "mouthColor" : 13,
    "eyesColor" : 96,
    "earsColor" : 10,
    //Cattributes
    "eyesShape" : 1,
    "decorationPattern" : 1,
    "decorationMidcolor" : 13,
    "decorationSidescolor" : 13,
    "animation" :  1,
    "lastNum" :  1
    }

// when page load
$( document ).ready(function() {
    $('#dnabody').html(defaultDNA.headColor);
    $('#dnamouth').html(defaultDNA.mouthColor);
    $('#dnaeyes').html(defaultDNA.eyesColor);
    $('#dnaears').html(defaultDNA.earsColor);
      
    $('#dnashape').html(defaultDNA.eyesShape);
    $('#dnadecoration').html(defaultDNA.decorationPattern);
    $('#dnadecorationMid').html(defaultDNA.decorationMidcolor);
    $('#dnadecorationSides').html(defaultDNA.decorationSidescolor);
    $('#dnaanimation').html(defaultDNA.animation);
    $('#dnaspecial').html(defaultDNA.lastNum);

  renderCat(defaultDNA);
});

function getDna(){
    var dna = ''
    dna += $('#dnabody').html()
    dna += $('#dnamouth').html()
    dna += $('#dnaeyes').html()
    dna += $('#dnaears').html()
    dna += $('#dnashape').html()
    dna += $('#dnadecoration').html()
    dna += $('#dnadecorationMid').html()
    dna += $('#dnadecorationSides').html()
    dna += $('#dnaanimation').html()
    dna += $('#dnaspecial').html()

    return parseInt(dna)
}

function renderCat(dna){
    headColor(colors[dna.headColor],dna.headColor)
    $('#bodycolor').val(dna.headColor)
    mouthColor(colors[dna.mouthColor],dna.mouthColor)
    $('#mouthcolor').val(dna.mouthColor)
    eyesColor(colors[dna.eyesColor],dna.eyesColor)
    $('#eyescolor').val(dna.eyesColor)
    earsColor(colors[dna.earsColor],dna.earsColor)
    $('#earscolor').val(dna.earsColor)
    //Cattributes section
    eyeVariation(dna.eyesShape)
    $('#eyesShape').val(dna.eyesShape)
    decorationVariation(dna.decorationPattern)
    $('#decorationPattern').val(dna.decorationPattern)
    decorationMidColor(colors[dna.decorationMidColor],dna.decorationMidColor)
    $('#decorationmid').val(dna.decorationMidColor)
    decorationSidesColor(colors[dna.decorationSidesColor],dna.decorationSidesColor)
    $('#decorationsides').val(dna.decorationSidesColor)
    animationVariation(dna.animation)
    $('#animation').val(dna.animation)
}

// Changing cat colors
$('#bodycolor').change(()=>{
    var colorVal = $('#bodycolor').val()
    headColor(colors[colorVal],colorVal)
})
$('#mouthcolor').change(()=>{
  var colorVal = $('#mouthcolor').val()
  mouthColor(colors[colorVal],colorVal)
})
$('#eyescolor').change(()=>{
  var colorVal = $('#eyescolor').val()
  eyesColor(colors[colorVal],colorVal)
})
$('#earscolor').change(()=>{
  var colorVal = $('#earscolor').val()
  earsColor(colors[colorVal],colorVal)
})
// Decoration colors
$('#decorationmid').change(()=>{
  var colorVal = $('#decorationmid').val()
  decorationMidColor(colors[colorVal],colorVal)
})
$('#decorationsides').change(()=>{
  var colorVal = $('#decorationsides').val()
  decorationSidesColor(colors[colorVal],colorVal)
})
// Changing cat attributes
$('#eyeshape').change(()=>{
  var shape = parseInt($('#eyeshape').val()) //between 1 and 7
  eyeVariation(shape)
})
$('#decorationpattern').change(()=>{
  var decorationPattern = parseInt($('#decorationpattern').val());
  decorationVariation(decorationPattern);
})
$('#animation').change(()=>{
  var animationVal = parseInt($('#animation').val()); //changes animationVal to 2 instead of "2"
  animationVariation(animationVal);
})
//Tabs
$(document).ready(function(){
  $(".nav-tabs a").click(function(){
    $(this).tab('show');
  });
});

function getRndInteger(min,max) {
  return Math.floor(Math.random() * max + min);
}

$('#randomCat').click(() => {
  
  colorVal=getRndInteger(10,89);
  $('#bodycolor').val(colorVal);
  headColor(colors[colorVal],colorVal);
  
  colorVal=getRndInteger(10,89);
  $('#mouthcolor').val(colorVal);
  mouthColor(colors[colorVal],colorVal);
  
  colorVal=getRndInteger(10,89);
  $('#eyescolor').val(colorVal)
  eyesColor(colors[colorVal],colorVal);

  colorVal=getRndInteger(10,89);
  $('#earscolor').val(colorVal);
  earsColor(colors[colorVal],colorVal);

  colorVal=getRndInteger(1,98);
  $('#decorationmid').val(colorVal);
  decorationMidColor(colors[colorVal],colorVal);

  colorVal=getRndInteger(1,98);
  $('#decorationsides').val(colorVal);
  decorationSidesColor(colors[colorVal],colorVal);

  shape=getRndInteger(1,7);
  $('#eyeshape').val(shape);
  eyeVariation(shape);

  decorationPattern=getRndInteger(1,5);
  $('#decorationpattern').val(decorationPattern);
  decorationVariation(decorationPattern);

  animationVal=getRndInteger(1,6);
  $('#animation').val(animationVal);
  animationVariation(animationVal);
})

$('#defaultCat').click(() =>{
  renderCat(defaultDNA);
})

$('#createNewCat').click(()=>{
  console.log("New Cat Created");
  //Will do this later
})
1 Like

Files/Code:

index.html
<meta charset="UTF-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Document</title>

<script type="text/javascript" src="assets/js/jquery-3.4.1.js"></script>

<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">

<script src="assets/bootstrap/js/popper.js"></script>

<script src="assets/bootstrap/js/bootstrap.min.js"></script>

<link rel="stylesheet" href="assets/css/mystyle.css">

<link rel="stylesheet" href="assets/css/cats.css">

<link rel="stylesheet" href="assets/css/colors.css">

<link rel="stylesheet" href="assets/css/factory.css">

<link rel="stylesheet" href="assets/css/frontend.css">

<link rel="stylesheet" href="assets/css/animations.css">
<div class="container p-5" style="margin-top: 12vh;margin-bottom: 10vh;">

    <div align="center">

        <h1 class="c-black">Kitties-Factory</h1>

        <p class="c-black">Create your custom Kitty</p>

    </div>

    <div class="row">

        <div class="col-lg-4 catBox m-2 light-b-shadow">

            <div id="cs-container">

                <div id="tail"></div>

                <div id="tail-mask"></div>

                <div id="tail-end"></div>

               

                <div id="body">

                    <div class="ear" id="ear-left">

                        <div class="ear-inner" id="ear-inner-left"></div>

                    </div>

                    <div class="ear" id="ear-right">

                        <div class="ear-inner" id="ear-inner-right"></div>

                    </div>

                   

                    <div id="mask"></div>

                   

                    <div id="patch">

                        <div class="fur"></div>

                        <div class="fur"></div>

                        <div class="fur"></div>

                    </div>

                   

                    <div id="eyes">

                        <div class="eye" id="eye-left">

                            <div class="tears"></div>

                            <div class="tears"></div>

                            <div class="shine" id="shine-left"></div>

                        </div>

                        <div class="eye" id="eye-right">

                            <div class="tears"></div>

                            <div class="tears"></div>

                            <div class="shine" id="shine-right"></div>

                        </div>

                    </div>

                   

                    <div id="whisk-left">

                        <div class="whisker" id="whisk-one"></div>

                        <div class="whisker"></div>

                        <div class="whisker" id="whisk-three"></div>

                    </div>

                   

                    <div id="nose"></div>

                   

                    <div id="whisk-right">

                        <div class="whisker" id="whisk-four"></div>

                        <div class="whisker"></div>

                        <div class="whisker" id="whisk-six"></div>

                    </div>

                   

                    <div id="smile">

                        <div id="smile-left-align">

                            <div id="smile-left"></div>

                            <div id="mask-left"></div>

                        </div>

                       

                        <div id="smile-right-align">

                            <div id="smile-right"></div>

                            <div id="mask-right"></div>

                        </div>

                    </div>

                   

                    <div id="tongue" class="tongueAnimation"></div>

                    <div id="tummy"></div>

                </div>

            </div>

            <br>

            <div class="dnaDiv" id="catDNA">

                <b>

                    DNA:

                    <!-- Colors -->

                    <span id="dnabody"></span>

                    <span id="dnaeyes"></span>

                    <span id="dnaears"></span>

                    <span id="dnabelly"></span>

                    <span id="dnastripes"></span>

                   

                    <!-- Cattributes -->

                    <span id="dnashape"></span>

                    <span id="dnadecoration"></span>

                    <span id="dnadecorationMid"></span>

                    <span id="dnadecorationSides"></span>

                    <span id="dnaanimation"></span>

                    <span id="dnaspecial"></span>

                </b>

            </div>

        </div>

        <div class="col-lg-7 cattributes m-2 light-b-shadow">

            <div class="catColors">

                <div class="btn-group">

                    <button type="button" class="btn btn-sm btn-primary" id="selectColor">Colors</button>

                    <button type="button" class="btn btn-sm btn-warning" id="selectAttr">Attributes</button>

                </div>

                <hr />

            </div>

            <div class="row">

                <div class="col-lg-6 col-md-6 col-sm-12">

                    <!-- Cat colors -->

                    <div id="catColors" class="color-selector">

                        <div class="form-group">

                            <label for="formControlRange"><b>Body</b><span class="badge badge-dark ml-2" id="headcode"></span></label>

                            <input type="range" min="10" max="98" class="form-control-range" id="bodycolor">

                        </div>

                    </div>

                </div>

                <div class="col-lg-6 col-md-6 col-sm-12">

                    <!-- Eyes colors -->

                    <div id="catColors" class="color-selector">

                        <div class="form-group">

                            <label for="formControlRange"><b>Eyes color</b><span class="badge badge-dark ml-2" id="eyecode"></span></label>

                            <input type="range" min="10" max="98" class="form-control-range" id="eyecolor">

                        </div>

                    </div>

                </div>

            </div>

            <!-- Ear & Tail colors -->

            <div id="catColors" class="color-selector">

                <div class="form-group">

                    <label for="formControlRange"><b>Ear | Tail</b><span class="badge badge-dark ml-2" id="ETcode"></span></label>

                    <input type="range" min="10" max="98" class="form-control-range" id="ETcolor">

                </div>

            </div>

            <!-- Inner Ear & Belly colors -->

            <div id="catColors" class="color-selector">

                <div class="form-group">

                    <label for="formControlRange"><b>Inner Ear | Belly</b><span class="badge badge-dark ml-2" id="IEBcode"></span></label>

                    <input type="range" min="10" max="98" class="form-control-range" id="IEBcolor">

                </div>

            </div>

            <!-- Eye Shape -->

            <div id="catColors" class="attr-selector">

                <div class="form-group">

                    <label for="formControlRange"><b>Eye Shape</b><span class="badge badge-dark ml-2" id="eyesShapecode"></span></label>

                    <input type="range" min="1" max="3" class="form-control-range" id="eyesShape">

                </div>

            </div>

            <!-- Decoration Style -->

            <div id="catColors" class="attr-selector">

                <div class="form-group">

                    <label for="formControlRange"><b>Decoration Style</b><span class="badge badge-dark ml-2" id="DStylecode"></span></label>

                    <input type="range" min="1" max="6" class="form-control-range" id="DStyle">

                </div>

            </div>

            <div class="row">

                <div class="col-lg-12 color-selector">

                    <div class="form-group">

                        <label for="">

                            <u><b>Decoration Colors:</b></u>

                        </label>

                    </div>

                </div>

                <div class="col-lg-6 col-md-6 col-sm-12 color-selector">

                    <!-- Decoration Center Color -->

                    <div class="form-group">

                        <label for="formControlRange">Mid Color<span class="badge badge-dark ml-2" id="DMcode"></span></label>

                        <input type="range" min="10" max="98" class="form-control-range" id="DMcolor">

                    </div>

                </div>

                <div class="col-lg-6 col-md-6 col-sm-12 color-selector">

                    <!-- Decoration Side Color -->

                    <div class="form-group">

                        <label for="formControlRange">Side Color<span class="badge badge-dark ml-2" id="DSidecode"></span></label>

                        <input type="range" min="10" max="98" class="form-control-range" id="DSidecolor">

                    </div>

                </div>

                <div class="col-lg-12 attr-selector">

                    <!-- Cat Animations -->

                    <div id="catColors">

                        <div class="form-group">

                            <label for="formControlRange"><b>Animation: </b><span class="badge badge-dark ml-2" id="animationCode"></span></label>

                            <input type="range" min="1" max="5" class="form-control-range" id="animateCat">

                        </div>

                    </div>

                </div>

            </div>

        </div>

        <div class="col-lg-11 cattributes m-2 light-b-shadow">

            <div class="form-group">

                <button type="button" class="btn btn-sm btn-primary" id="randomBtn">Get Random Kitty</button>

                <button type="button" class="btn btn-sm btn-warning" id="defaultBtn">Default Kitty</button>

                <button type="button" class="btn btn-sm btn-success" id="createBtn">Create New Kitty</button>

            </div>

        </div>

    </div>

    <br/>

   

</div>

<footer align="left">

    <p>Angnima Sherpa - 2022</p>

</footer>
catSettings.js

var colors = Object.values(allColors())

var defaultDNA = {

"headcolor" : 10,

"tummyColor" : 55,

"eyesColor" : 89,

"earsColor" : 10,

"stripesColor" : 90,

//Cattributes

"eyesShape" : 1,

"decorationPattern" : 1,

"decorationMidcolor" : 90,

"decorationSidescolor" : 14,

"animation" :  1,

"lastNum" :  1

}

// when page load

$( document ).ready(function() {

$(’#dnabody’).html(defaultDNA.headColor);

$(’#dnamouth’).html(defaultDNA.mouthColor);

$(’#dnaeyes’).html(defaultDNA.eyesColor);

$(’#dnaears’).html(defaultDNA.earsColor);

$(’#dnashape’).html(defaultDNA.eyesShape)

$(’#dnadecoration’).html(defaultDNA.decorationPattern)

$(’#dnadecorationMid’).html(defaultDNA.decorationMidcolor)

$(’#dnadecorationSides’).html(defaultDNA.decorationSidescolor)

$(’#dnaanimation’).html(defaultDNA.animation)

// $(’#dnaspecial’).html(defaultDNA.lastNum)

renderCat(defaultDNA)

});

function getDna(){

var dna = ''

dna += $('#dnabody').html()

dna += $('#dnamouth').html()

dna += $('#dnaeyes').html()

dna += $('#dnaears').html()

dna += $('#dnashape').html()

dna += $('#dnadecoration').html()

dna += $('#dnadecorationMid').html()

dna += $('#dnadecorationSides').html()

dna += $('#dnaanimation').html()

dna += $('#dnaspecial').html()

return parseInt(dna)

}

function renderCat(dna){

$('#bodycolor').val(dna.headcolor)

headColor(colors[dna.headcolor],dna.headcolor)

$('#eyecolor').val(dna.eyesColor)

eyeColor(colors[dna.eyesColor],dna.eyesColor)

$('#ETcolor').val(dna.earsColor)

ETColor(colors[dna.earsColor],dna.earsColor)

$('#IEBcolor').val(dna.tummyColor)

IEBColor(colors[dna.tummyColor],dna.tummyColor)

$('#eyesShape').val(dna.eyesShape)

EyeShape(dna.eyesShape)

$('#SWcolor').val(dna.stripesColor)

SWColor(colors[dna.stripesColor],dna.stripesColor)

$('#DStyle').val(dna.decorationPattern)

changeDStyle(dna.decorationPattern)

$('#DMcolor').val(dna.decorationMidcolor)

DMColor(colors[dna.decorationMidcolor], dna.decorationMidcolor);

$("#DSidecolor").val(dna.decorationSidescolor);

DSideColor(colors[dna.decorationSidescolor], dna.decorationSidescolor);

$("#animateCat").val(dna.animation);

changeAnimation(dna.animation);

}

// Changing cat colors

$(’#bodycolor’).change(()=>{

var colorVal = $('#bodycolor').val()

headColor(colors[colorVal], colorVal)

})

$(’#eyecolor’).change(()=>{

var colorVal = $(’#eyecolor’).val()

eyeColor(colors[colorVal], colorVal)

})

$(’#ETcolor’).change(()=>{

var colorVal = $(’#ETcolor’).val()

ETColor(colors[colorVal], colorVal)

})

$(’#IEBcolor’).change(()=>{

var colorVal = $(’#IEBcolor’).val()

IEBColor(colors[colorVal], colorVal)

})

$(’#eyesShape’).change(()=>{

var shapeVal = $(’#eyesShape’).val()

EyeShape(shapeVal)

})

$(’#DStyle’).change(()=>{

var StyleVal = $(’#DStyle’).val()

changeDStyle(StyleVal)

})

$(’#SWcolor’).change(()=>{

var colorVal = $(’#SWcolor’).val()

SWColor(colors[colorVal], colorVal)

})

$(’#DMcolor’).change(()=>{

var colorVal = $(’#DMcolor’).val()

DMColor(colors[colorVal], colorVal)

})

$(’#DSidecolor’).change(()=>{

var colorVal = $(’#DSidecolor’).val()

DSideColor(colors[colorVal], colorVal)

})

$("#animateCat").change(() => {

var animateVal = $("#animateCat").val()

changeAnimation(animateVal);

})

// BTN Change

$("#randomBtn").click(getRandomKitty)

function getRandomKitty() {

let headColor_dna = getRandomDnaNum();

$(’#bodycolor’).val(headColor_dna)

headColor(colors[headColor_dna], headColor_dna)

let eyeColor_dna = getRandomDnaNum();

$(’#eyecolor’).val(eyeColor_dna)

eyeColor(colors[eyeColor_dna], eyeColor_dna)

let ETColor_dna = getRandomDnaNum();

$(’#ETcolor’).val(ETColor_dna)

ETColor(colors[ETColor_dna], ETColor_dna)

let IEBColor_dna = getRandomDnaNum();

$(’#IEBcolor’).val(IEBColor_dna)

IEBColor(colors[IEBColor_dna], IEBColor_dna)

let eyeShape_dna = Math.floor(Math.random() * 3) + 1;

$(’#eyesShape’).val(eyeShape_dna)

EyeShape(eyeShape_dna)

let SWColor_dna = getRandomDnaNum();

$(’#SWcolor’).val(SWColor_dna)

SWColor(colors[SWColor_dna], SWColor_dna)

let DStyle_dna = Math.floor(Math.random() * 6) + 1;

$(’#DStyle’).val(DStyle_dna)

changeDStyle(DStyle_dna)

let DMColor_dna = getRandomDnaNum();

$(’#DMcolor’).val(DMColor_dna)

DMColor(colors[DMColor_dna], DMColor_dna);

let DSideColor_dna = getRandomDnaNum();

$("#DSidecolor").val(DSideColor_dna);

DSideColor(colors[DSideColor_dna], DSideColor_dna);

let animate_dna = Math.floor(Math.random() * 5) + 1;

$("#animateCat").val(animate_dna);

changeAnimation(animate_dna);

}

function getRandomDnaNum() {

return Math.floor(Math.random() * 89) + 10

}

$("#defaultBtn").click(() => {

renderCat(defaultDNA)

})

catFactory.js

//Random color

function getColor() {

var randomColor = Math.floor(Math.random() * 16777215).toString(16);

return randomColor

}

function genColors(){

var colors = []

for(var i = 10; i < 99; i ++){

  var color = getColor()

  colors[i] = color

}

return colors

}

//This function code needs to modified so that it works with Your cat code.

function headColor(color,code) {

$('#body, #mask, #mask-right, #smile-right, #mask-left, #smile-left').css('background-color', '#' + color)  //This changes the color of the cat

// $("#tail").css("border", "15px solid #" + color);

// $("#tail-end").css("background-color", "#" + color);

$('#headcode').html('code: '+code) //This updates text of the badge next to the slider

$('#dnabody').html(code) //This updates the body color part of the DNA that is displayed below the cat

}

function eyeColor(color,code) {

$('.eye').css('background-color', '#' + color)  //This changes the color of the cat

$('#eyecode').html('code: '+code) //This updates text of the badge next to the slider

$('#dnaeyes').html(code) //This updates the body color part of the DNA that is displayed below the cat

}

function ETColor(color,code) {

$("#tail").css("border", "15px solid #" + color);

$("#tail-end").css("background-color", "#" + color);

$(".ear").css("background-color", "#" + color);



$('#ETcode').html('code: '+code) //This updates text of the badge next to the slider

$('#dnaears').html(code) //This updates the body color part of the DNA that is displayed below the cat

}

function IEBColor(color,code) {

$(".ear-inner").css("background-color", "#" + color);

$("#tummy").css("background-color", "#" + color);



$('#IEBcode').html('code: '+code) //This updates text of the badge next to the slider

$('#dnabelly').html(code) //This updates the body color part of the DNA that is displayed below the cat

}

function SWColor(color,code) {

$(".fur").css("background-color", "#" + color);



$('#SWcode').html('code: ' + code); //This updates text of the badge next to the slider

$('#dnastripes').html(code) //This updates the body color part of the DNA that is displayed below the cat

}

function DMColor(color, code) {

$(".fur:odd").css("background-color", "#" + color);

$('#DMcode').html('code: ' + code);

$('#dnadecorationMid').html(code);

}

function DSideColor(color, code) {

$(".fur:even").css("background-color", "#" + color);

$('#DSidecode').html('code: ' + code);

$('#dnadecorationSides').html(code);

}

function changeAnimation(code) {

code = parseInt(code);

$("#dnaanimation").html(code);



removeAllAnimations()

switch (code) {

    case 1:

        $("#animationCode").html("None");

        break;

    case 2:

        animationType2();

        break;

    case 3:

        animationType3();

        break;

    case 4:

        animationType4();

        break;

    case 5:

        animationType5();

        break;

    default:

        break;

}

}

function animationType2() {

$(".shine").addClass("eyesMovement");

$("#animationCode").html("Eyes");

}

function animationType3() {

$(".ear").addClass("earsMovement");

$("#animationCode").html("Ears");

}

function animationType4() {

$(".tears").addClass("tearsMovement");

$("#smile-left, #mask-left, #smile-right, #mask-right").addClass("flip-item");

$("#mask-left, #mask-right").addClass("margin-15pc");

$("#tongue").addClass("hide");

$("#animationCode").html("Tears");

}

function animationType5() {

$("#tongue").addClass("tongueAnimation");

$("#animationCode").html("Tongue");

}

function removeAllAnimations() {

$(".shine").removeClass("eyesMovement");

$(".ear").removeClass("earsMovement");

$(".tears").removeClass("tearsMovement");

$("#smile-left, #mask-left, #smile-right, #mask-right").removeClass("flip-item");

$("#mask-left, #mask-right").removeClass("margin-15pc");

$("#tongue").removeClass("hide");

$("#tongue").removeClass("tongueAnimation");

}

function EyeShape(code) {

normalEyes()

$("#dnashape").html(code)

if(code == 3) {

    $(".eye").css("border-top", "6px solid");

    $("#eyesShapecode").html("Sleepy");

}else if(code == 2) {

    $(".eye").css("border-bottom", "6px solid");

    $("#eyesShapecode").html("Sus");

}else {

    $(".eye").css("border-top", "none");

    $("#eyesShapecode").html("Basic");

}

}

function changeDStyle(style) {

style = parseInt(style)

$("#dnadecoration").html(style)

switch (style) {

    case 1:

        normalDStyle()

        $('#DStylecode').html('Basic');

        break;

    case 2:

        normalDStyle()

        $(".fur:first").css("transform", "translate(9px, 10px)")

        $('#DStylecode').html('Ping');

        break;

    case 3:

        normalDStyle()

        $(".fur:first").css("transform", "translate(9px, 10px)")

        $(".fur:last").css("transform", "rotate(90deg) translate(3px, 9px)");

        $('#DStylecode').html('Cross');

        break;

    case 4:

        normalDStyle()

        $(".fur:first").css("transform", "rotate(90deg) translate(6px, -9px)");

        $(".fur:last").css("transform", "rotate(90deg) translate(3px, 9px)");

        $('#DStylecode').html('Pyramid');

        break;

    case 5:

        normalDStyle()

        $(".fur:first").css("transform", "translate(9px, 20px)");

        $(".fur:last").css("transform", "rotate(90deg) translate(3px, 9px)");

        $('#DStylecode').html('Guru');

        break;

    case 6:

        normalDStyle()

        $(".fur:first").css("transform", "translate(9px, 10px) rotate(90deg)");

        $(".fur:last").css("transform", "translate(-9px, 6px)");

        $('#DStylecode').html('Gunner');

        break;

    default:

        normalDStyle()

        $('#DStylecode').html('Basic');

        break;

}

}

//###################################################

//Functions below will be used later on in the project

//###################################################

function eyeVariation(num) {

$('#dnashape').html(num)

switch (num) {

    case 1:

        normalEyes()

        $('#eyeName').html('Basic')

        break

}

}

function decorationVariation(num) {

$('#dnadecoration').html(num)

switch (num) {

    case 1:

        $('#decorationName').html('Basic')

        normaldecoration()

        break

}

}

async function normalEyes() {

await $('.eye').css('border', 'none')

}

async function normalDStyle() {

await $(".fur").css("transform", "none");

}

async function normaldecoration() {

//Remove all style from other decorations

//In this way we can also use normalDecoration() to reset the decoration style

$('.cat__head-dots').css({ "transform": "rotate(0deg)", "height": "48px", "width": "14px", "top": "1px", "border-radius": "0 0 50% 50%" })

$('.cat__head-dots_first').css({ "transform": "rotate(0deg)", "height": "35px", "width": "14px", "top": "1px", "border-radius": "50% 0 50% 50%" })

$('.cat__head-dots_second').css({ "transform": "rotate(0deg)", "height": "35px", "width": "14px", "top": "1px", "border-radius": "0 50% 50% 50%" })

}

2 Likes

Hello, this is my code:
The only problem I have is when I click the random button the mid pattern color changes but does not move the bar slider.


index.html:

<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Academy Penguin </title>
  <script type="text/javascript" src="/Penguin NFT Marketplace/js/jquery-3.4.1.js"></script>
  <link rel="stylesheet" href="/Penguin NFT Marketplace/bootstrap/css/bootstrap.min.css">
  <script src="/Penguin NFT Marketplace/bootstrap/js/popper.js"></script>
  <script src="/Penguin NFT Marketplace/bootstrap/js/bootstrap.min.js"></script>

  <link rel="stylesheet" href="/Penguin NFT Marketplace/css/mystyle.css">
  <link rel="stylesheet" href="/Penguin NFT Marketplace/css/penguin.css">
  <link rel="stylesheet" href="/Penguin NFT Marketplace/css/colors.css">
  <link rel="stylesheet" href="/Penguin NFT Marketplace/css/factory.css">
  <link rel="stylesheet" href="/Penguin NFT Marketplace/css/frontend.css">
  <link rel="stylesheet" href="/Penguin NFT Marketplace/css/animations.css">
  <link rel="stylesheet" href="/Penguin NFT Marketplace/css/button.css">


</head>
  <body>
    <div class="container p-5" style="margin-top: 12vh;margin-bottom: 10vh;">
        <div align="center">
        <h1 class="c-white">Penguin-Factory</h1>
        <p class="c-white">Create your custom Penguin</p>
        <button onclick="randomPenguin()" class="randomPenguin">Random Penguin</button>
        <button onclick="defaultPenguin()"class="defaultPenguin">Default Penguin</button>
        <button class="createPenguin">Create new Penguin</button>
        <button onclick="buttonColor()" class="colorsB">Colors</button>
        <button onclick="buttonPattern()" class="attributesB">Patterns and Attributes</button>

    </div>
        <div class="row">
            <div class="col-lg-4 penguinBox m-2 light-b-shadow">
                <div class="penguin ">
                    <div class="penguin-bottom">
                    <div class="right-hand"></div> 
                    <div class="left-hand"></div>
                    <div class="right-feet"></div>
                    <div class="left-feet"></div>
                    </div>

                    <div id="head" class="penguin-top">
                      <div class="belly"></div>
                        
                        <div class="pattern"></div>
                        <div class="pattern-left"></div>
                        <div class="pattern-right"></div>
                        <div class="left-cheek"></div>
                        <div class="right-cheek"></div>
                        <div class="beak-bottom"></div>
                        <div class="beak-top"></div>
                        <div class="blush-left"></div>
                        <div class="blush-right"></div>
                        <div class="left-eye">
                          <div class="sparkle"></div>
                        </div>
                        <div class="right-eye">
                          <div class="sparkle"></div>
                        </div>
                        

                    </div>



                    
                </div>
                <br>
                <div class="dnaDiv" id="penguinDNA">
                    <b>
                        DNA:
                        <!-- Colors -->
                         <span id="dnabody"></span>
                         <span id="dnabelly"></span>
                         <span id="dnaface"></span>
                         <span id="dnahand"></span>
                        
                         <!-- attributes -->
                         <span id="dnashape"></span>
                         <span id="dnadecoration"></span>
                         <span id="dnadecorationMid"></span>
                         <span id="dnadecorationSides"></span>
                         <span id="dnaanimation"></span>
                         <span id="dnaspecial"></span>
                    </b>
                </div>
            </div>
            <div class="col-lg-7 attributes m-2 light-b-shadow">


<!-- Penguin colors -->
<div id="penguinColors">
                <div class="form-group">
                    <label for="formControlRange"><b>Head and body</b><span class="badge badge-dark ml-2" id="headcode"></span></label>
                    <input type="range" min="10" max="98" class="form-control-range" id="bodycolor">
                </div>
                <div class="form-group">
                    <label for="formControlRange"><b>Belly</b><span class="badge badge-dark ml-2" id="bellycode"></span></label>
                    <input type="range" min="10" max="98" class="form-control-range" id="bellycolor">
                </div>  
                <div class="form-group">
                  <label for="formControlRange"><b>Face</b><span class="badge badge-dark ml-2" id="facecode"></span></label>
                  <input type="range" min="10" max="98" class="form-control-range" id="facecolor">
                </div>
                <div class="form-group">
                  <label for="formControlRange"><b>Hands</b><span class="badge badge-dark ml-2" id="handcode"></span></label>
                  <input type="range" min="10" max="98" class="form-control-range" id="handcolor">
                </div>
                <div class="form-groupP">
                  <label for="formControlRange"><b>Eye shape</b><span class="badge badge-dark ml-2" id="eyeName"></span></label>
                  <input type="range" min="1" max="7" class="form-control-range" id="eyeshape">
                </div>
                <div class="form-groupP">
                  <label for="formControlRange"><b>Pattern</b><span class="badge badge-dark ml-2" id="decorationPattern"></span></label>
                  <input type="range" min="1" max="7" class="form-control-range" id="patternshape">
                </div>
                <div class="form-groupP">
                  <label for="formControlRange"><b>Pattern Color Mid</b><span class="badge badge-dark ml-2" id="decorationMidcolor"></span></label>
                  <input type="range" min="10" max="98" class="form-control-range" id="patterncolormid">
                </div>
                <div class="form-groupP">
                  <label for="formControlRange"><b>Pattern Color Sides</b><span class="badge badge-dark ml-2" id="decorationSidescolor"></span></label>
                  <input type="range" min="10" max="98" class="form-control-range" id="patterncolorsides">
                </div>
                <div class="form-groupP">
                  <label for="formControlRange"><b>Animation</b><span class="badge badge-dark ml-2" id="animationName"></span></label>
                  <input type="range" min="1" max="6" class="form-control-range" id="animation">
                </div>
              </div>

            </div>

            </div>
            <br>

        </div>



    </div>
    <footer align="left">
        <p>Ivan on Tech Academy Bootcamp July 2020</p>
    </footer>

  </body>
  <script src="/Penguin NFT Marketplace/js/colors.js"></script>
  <script src="/Penguin NFT Marketplace/js/penguinFactory.js"></script>
  <script src="/Penguin NFT Marketplace/js/penguinSettings.js"></script>
  <script src="/Penguin NFT Marketplace/js/button.js"></script>


</html>

button.js:

function buttonColor() {
    $('.form-groupP').css('display', 'none');
    $('.form-group').css('display', 'unset');
}

function buttonPattern() {
    $('.form-group').css('display', 'none');
    $('.form-groupP').css('display', 'unset');
}

penguinSettings.js:

var colors = Object.values(allColors())

var defaultDNA = {
    "headColor" : 10,
    "bellyColor" : 13,
    "faceColor" : 13,
    "handColor" : 10,
    
    //attributes
    "eyesShape" : 1,
    "decorationPattern" : 1,
    "decorationMidcolor" : 13,
    "decorationSidescolor" : 13,
    "animation" :  1,
    "lastNum" :  1,
    }

// when page load
$( document ).ready(function() {
  $('#dnabody').html(defaultDNA.headColor);
  $('#dnabelly').html(defaultDNA.bellyColor);
  $('#dnaface').html(defaultDNA.faceColor);
  $('#dnahand').html(defaultDNA.handColor);
  $('#dnashape').html(defaultDNA.eyesShape)
  $('#dnadecoration').html(defaultDNA.decorationPattern)
  $('#dnadecorationMid').html(defaultDNA.decorationMidcolor)
  $('#dnadecorationSides').html(defaultDNA.decorationSidescolor)
  $('#dnaanimation').html(defaultDNA.animation)
  $('#dnaspecial').html(defaultDNA.lastNum)

  renderPenguin(defaultDNA)
});

function getDna(){
    var dna = ''
    dna += $('#dnabody').html()
    dna += $('#dnabelly').html()
    dna += $('#dnaface').html()
    dna += $('#dnahand').html()
    dna += $('#dnashape').html()
    dna += $('#dnadecoration').html()
    dna += $('#dnadecorationMid').html()
    dna += $('#dnadecorationSides').html()
    dna += $('#dnaanimation').html()
    dna += $('#dnaspecial').html()

    
    return parseInt(dna)
}

function defaultPenguin() {
  $('#dnabody').html(defaultDNA.headColor);
  $('#dnabelly').html(defaultDNA.bellyColor);
  $('#dnaface').html(defaultDNA.faceColor);
  $('#dnahand').html(defaultDNA.handColor);
  $('#dnashape').html(defaultDNA.eyesShape)
  $('#dnadecoration').html(defaultDNA.decorationPattern)
  $('#dnadecorationMid').html(defaultDNA.decorationMidcolor)
  $('#dnadecorationSides').html(defaultDNA.decorationSidescolor)
  $('#dnaanimation').html(defaultDNA.animation)
  $('#dnaspecial').html(defaultDNA.lastNum)

  renderPenguin(defaultDNA)
}

function randomPenguin(){
    var randomDNA = {
      "headColor" : Math.floor(Math.random() * 89) + 10,
      "bellyColor" : Math.floor(Math.random() * 89) + 10,
      "faceColor" : Math.floor(Math.random() * 89) + 10,
      "handColor" : Math.floor(Math.random() * 89) + 10,
      "eyesShape" : Math.floor(Math.random() * 7) + 1,
      "decorationPattern" : Math.floor(Math.random() * 4) + 1,
      "decorationMidcolor" : Math.floor(Math.random() * 6) + 1,
      "decorationSidescolor" : Math.floor(Math.random() * 89) + 10,
      "animation" : Math.floor(Math.random() * 4) + 1,
      "lastNum" : 1,
    }
    $('#dnabody').html(randomDNA.headColor);
    $('#dnabelly').html(randomDNA.bellyColor);
    $('#dnaface').html(randomDNA.faceColor);
    $('#dnahand').html(randomDNA.handColor);
    $('#dnashape').html(randomDNA.eyesShape);
    $('#dnadecoration').html(randomDNA.decorationPattern);
    $('#dnadecorationMid').html(randomDNA.decorationMidcolor);
    $('#dnadecorationSides').html(randomDNA.decorationSidescolor);
    $('#dnaanimation').html(randomDNA.animation);
    renderPenguin(randomDNA);
}


function renderPenguin(dna){

    headColor(colors[dna.headColor],dna.headColor)
    $('#bodycolor').val(dna.headColor)

    bellyColor(colors[dna.bellyColor],dna.bellyColor)
    $('#bellycolor').val(dna.bellyColor)

    faceColor(colors[dna.faceColor],dna.faceColor)
    $('#facecolor').val(dna.faceColor)

    handColor(colors[dna.handColor],dna.handColor)
    $('#handcolor').val(dna.handColor)

    eyeVariation(dna.eyesShape)
    $('#eyeshape').val(dna.eyesShape)

    decorationVariation(dna.decorationPattern)
    $('#patternshape').val(dna.decorationPattern)
    
    patternColorMid(colors[dna.decorationMidcolor],dna.decorationMidcolor)
    $('#patterncolormid').val(dna.decorationMidcolor)

    patternColorSides(colors[dna.decorationSidescolor],dna.decorationSidescolor)
    $('#patterncolorsides').val(dna.decorationSidescolor)

    animationVariation(dna.animation)
    $('#animation').val(dna.animation)


// Changing penguin colors

$('#bodycolor').change(()=>{
    var colorVal = $('#bodycolor').val()    
    headColor(colors[colorVal],colorVal)
})

$('#bellycolor').change(()=>{
    var colorVal = $('#bellycolor').val()
    bellyColor(colors[colorVal],colorVal)
})

$('#facecolor').change(()=>{
    var colorVal = $('#facecolor').val()
    faceColor(colors[colorVal],colorVal)
})

$('#handcolor').change(()=>{
    var colorVal = $('#handcolor').val()
    handColor(colors[colorVal],colorVal)
})

$('#patterncolormid').change(()=>{
    var colorVal = $('#patterncolormid').val()
    patternColorMid(colors[colorVal],colorVal)
})

$('#patterncolorsides').change(()=>{
    var colorVal = $('#patterncolorsides').val()
    patternColorSides(colors[colorVal],colorVal)
    console.log("1")
})

//Eye Shape

$('#eyeshape').change(()=>{
    var shape = parseInt($('#eyeshape').val())
    eyeVariation(shape)
})

$('#patternshape').change(()=>{
    var pattern = parseInt($('#patternshape').val())
    decorationVariation(pattern)
})

$('#animation').change(()=>{
    var animation = parseInt($('#animation').val())
    animationVariation(animation)
})

}




1 Like

Tabs, 4 defaults (just for fun), random cat generator and Create Cat (non-functioning).
Kitty Clone

index.html
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Academy kitties </title>
  <script type="text/javascript" src="assets/js/jquery-3.4.1.js"></script>
  <link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
  <script src="assets/bootstrap/js/popper.js"></script>
  <script src="assets/bootstrap/js/bootstrap.min.js"></script>

  <link rel="stylesheet" href="assets/css/animations.css">
  <link rel="stylesheet" href="assets/css/mystyle.css">
  <link rel="stylesheet" href="assets/css/cats1.css">
  <link rel="stylesheet" href="assets/css/colors.css">
  <link rel="stylesheet" href="assets/css/factory2.css">
  <link rel="stylesheet" href="assets/css/frontend.css">
</head>
  <body>
    <div class="container p-5" style="margin-bottom: 10vh;">
        <div align="center">
            <h1 class="c-white">Kitties-Factory</h1>
            <p class="c-white">Create your custom Kitty</p>
        </div>
        <div class="row">
            <div class="col-lg-4 catBox m-2 light-b-shadow">
                <div class="cat">
                    <div class="ears">
                        <div id="left_ear" class="ear left_ear">
                            <div class="inner_ear left_inner_ear"></div>
                        </div>
                        <div class="ear right_ear">
                            <div class="inner_ear right_inner_ear"></div>
                        </div>
                    </div>
                    <div class="head">
                        <div class="eyes">
                            <div class="eye left_eye">
                                <div class="irus">
                                    <span class="pupils"></span>
                                </div>
                             
                                <div class="reflection_1"></div>
                                <div class="reflection_2"></div>
                            </div>
                            <div class="eye right_eye">
                                <div class="irus">
                                    <span class="pupils"></span>
                                </div>
                       
                                <div class="reflection_1"></div>
                                <div class="reflection_2"></div>
                            </div>
                        </div>
                        <span3 class="snout"></span3>
                        <div class="nose"></div>
                        <div class="mouth-left"></div>
                        <div class="mouth-right"></div>
                        <span2 class="forehead_markings_middle"></span2>
                        <span2 class="forehead_markings_left"></span2>
                        <span2 class="forehead_markings_right"></span2>
                        <div id="whisker_mid_left" class="whisker whisker_mid_left"></div>
                        <div id="whisker_top_left" class="whisker whisker_top_left"></div>
                        <div id="whisker_bottom_left" class="whisker whisker_bottom_left"></div>
                        <div id="whisker_mid_right" class="whisker whisker_mid_right"></div>                       
                        <div id="whisker_top_right" class="whisker whisker_top_right"></div>
                        <div id="whisker_bottom_right" class="whisker whisker_bottom_right"></div>               
                    </div>
                    <div class="torso">
                    <div class="chest"></div>
                    <div class="stomach"></div>
                    <div class="paw_front_left">
                        <span2 class="paw_stripe"></span2>
                        <span2 class="paw_stripe bottom_stripe"></span2>
                    </div>
                    <div class="paw_front_right">
                        <span2 class="paw_stripe"></span2>
                        <span2 class="paw_stripe bottom_stripe"></span2>
                    </div>
                    <div class="paw_back_right"></div>
                    <div class="paw_back_left"></div>
                    <div id="tail" class="tail">
                        <span2 class="tail_marking"></span2>
                        <span2 class="tail_marking bottom_marking"></span2>
                    </div> 
                </div>
                </div>

                <div class="dnaDiv" id="catDNA">
                    <b>
                        DNA:
                        <!-- Colors -->
                         <span id="dnabody"></span>
                         <span id="dnapaw"></span>
                         <span id="dnamarking"></span>
                         <span id="dnasnout"></span>
                         <span id="dnaeye"></span>
                        
                         <!-- Cattributes -->
                         <span id="dnashape"></span>
                         <span id="dnadecoration"></span>
                         <span id="dnasnouttype"></span>
                         <span id="dnasnoutOnly"></span>
                         <span id="dnastomachOnly"></span>
                         <span id="dnainnerEarOnly"></span>
                         <span id="dnamarkingsOnly"></span>
                         <span id="dnaanimation"></span>
                         <span id="dnaspecial"></span>
                    </b>
                </div>
            </div>
            
    <div class="col-lg-7 cattributes m-2 light-b-shadow">
        <!-- Cat colors -->
        <div id="catColors">
            <div class="btn btn-group-toggle" data-toggle="buttons">
                <label class="btn btn-primary active colors">
                  <input type="radio" name="options" id="option1" autocomplete="off" checked> Color Combos
                </label>
                <label class="btn btn-primary colors2">
                  <input type="radio" name="options" id="option2" autocomplete="off"> Details
                </label>
              </div>
            <p></p>

            <div class="tab colors">
                <div class="form-group">
                    <label for="formControlRange"><b>Head | Body</b><span class="badge badge-dark ml-2" id="headcode"></span></label>
                    <input type="range" min="10" max="98" class="form-control-range" id="bodycolor">
                </div>
                <div class="form-group">
                    <label for="formControlRange"><b>Ears | Paws | Tail</b><span class="badge badge-dark ml-2" id="pawcode"></span></label>
                    <input type="range" min="10" max="98" class="form-control-range" id="pawcolor">
                </div>
                <div class="form-group">
                    <label for="formControlRange"><b>Markings | Inner Ear</b><span class="badge badge-dark ml-2" id="markingcode"></span></label>
                    <input type="range" min="10" max="98" class="form-control-range" id="markingcolor">
                </div>
                <div class="form-group">
                    <label for="formControlRange"><b>Snout | Stomach</b><span class="badge badge-dark ml-2" id="snoutcode"></span></label>
                    <input type="range" min="10" max="98" class="form-control-range" id="snoutcolor">
                </div>
                <div class="form-group">
                    <label for="formControlRange"><b>Eyes</b><span class="badge badge-dark ml-2" id="eyecode"></span></label>
                    <input type="range" min="10" max="98" class="form-control-range" id="eyecolor">
                </div>
            </div>

            <div class="tab colors2">
                <p></p>
                <b>Styles | Animations</b>
                <p></p>
                <div class="row">
                    <div class="col">
                        <label for="formControlRange"><b style="color:rgb(114, 95, 41)">Pupil</b><span class="badge badge-dark ml-2" id="eyename"></span></label>
                        <input type="range" min="1" max="3" class="form-control-range" id="eyeshape">
                    </div>
                    <div class="col">
                        <label for="formControlRange"><b style="color:rgb(114, 95, 41)">Markings</b><span class="badge badge-dark ml-2" id="markingsName"></span></label>
                        <input type="range" min="1" max="3" class="form-control-range" id="markingsOnOff">
                    </div>
                </div>
                <p></p>
                <div class="row">
                    <div class="col">
                        <label for="formControlRange"><b style="color:rgb(114, 95, 41)">Snout</b><span class="badge badge-dark ml-2" id="snoutName"></span></label>
                        <input type="range" min="1" max="4" class="form-control-range" id="snoutType">
                    </div>
                    <div class="col">
                    <label for="formControlRange"><b style="color:rgb(114, 95, 41)">Animation</b><span class="badge badge-dark ml-2" id="animationName"></span></label>
                    <input type="range" min="1" max="4" class="form-control-range" id="animationType">
                    </div> 
                </div>
                <p></p>

                <div class="font-weight-bold">Seperate Colors</div>
                <p></p>
                <div class="row">
                    <div class="col">
                        <label for="formControlRange"><b style="color:rgb(114, 95, 41)">Snout Color</b><span class="badge badge-dark ml-2" id="snoutOnlycode"></span></label>
                        <input type="range" min="10" max="98" class="form-control-range" id="snoutOnlycolor">
                    </div>
                    <div class="col">
                        <label for="formControlRange"><b style="color:rgb(114, 95, 41)">Stomach Color</b><span class="badge badge-dark ml-2" id="stomachOnlycode"></span></label>
                        <input type="range" min="10" max="98" class="form-control-range" id="stomachOnlycolor">
                    </div>
                </div>
                <p></p>
                <div class="row">
                    <div class="col">
                        <label for="formControlRange"><b style="color:rgb(114, 95, 41)">Inner Ear Color</b><span class="badge badge-dark ml-2" id="innerEarOnlycode"></span></label>
                        <input type="range" min="10" max="98" class="form-control-range" id="innerEarOnlycolor">
                    </div>
                    <div class="col">
                        <label for="formControlRange"><b style="color:rgb(114, 95, 41)">Marking Color</b><span class="badge badge-dark ml-2" id="markingsOnlycode"></span></label>
                        <input type="range" min="10" max="98" class="form-control-range" id="markingsOnlycolor">
                    </div>
                </div>
        </div>
        </div>
        </div>
        </div>
            <div style="padding-left: 60px; padding-top: 5px">
                <button type="button" class="btn btn-primary light-b-shadow random" style="margin-right: 13vh"> Generate Random Cat</button>
                <button type="button" class="btn btn-primary light-b-shadow tabby">Tabby</button>
                <button type="button" class="btn btn-primary light-b-shadow burmese">Burmese</button>
                <button type="button" class="btn btn-primary light-b-shadow tuxedo">Tuxedo</button>
                <button type="button" class="btn btn-primary light-b-shadow british">British Shorthair</button>
                <button type="button" class="btn btn-success light-b-shadow" style="float: right; margin-right: 75px">Create Cat</button>
            </div>



        
    </div>
    <footer align="left">
        <p>Ivan on Tech Academy Bootcamp July 2020</p>
    </footer>

  </body>
  <script src="assets/js/colors2.js"></script>
  <script src="assets/js/catSettings.js"></script>
  <script src="assets/js/catFactory.js"></script>

</html>

catSettings.js

var colors = Object.values(allColors())

var defaultDNA = {
    "headcolor" : 10,
    "pawcolor" : 10,
    "markingcolor" : 20,
    "snoutcolor" : 30,
    "eyecolor" : 41,
    //Cattributes
    "eyesShape" : 2,
    "decorationOnOff" : 1,
    "snoutStyle": 1,
    "snoutOnlycolor" : 30,
    "stomachOnlycolor" : 30,
    "innerEarOnlycolor" : 20,
    "markingsOnlycolor" : 20,
    "animation" :  1,
//    "lastNum" :  1
    }

var burmeseDNA = {
    "headcolor" : 25,
    "pawcolor" : 15,
    "markingcolor" : 20,
    "snoutcolor" : 30,
    "eyecolor" : 29,
    //Cattributes
    "eyesShape" : 2,
    "decorationOnOff" : 2,
    "snoutStyle": 2,
    "snoutOnlycolor" : 15,
    "stomachOnlycolor" : 10,
    "innerEarOnlycolor" : 10,
    "markingsOnlycolor" : 20,
    "animation" :  1,
}

var tuxedoDNA = {
  "headcolor" : 60,
  "pawcolor" : 60,
  "markingcolor" : 20,
  "snoutcolor" : 30,
  "eyecolor" : 70,
  //Cattributes
  "eyesShape" : 2,
  "decorationOnOff" : 2,
  "snoutStyle": 3,
  "snoutOnlycolor" : 15,
  "stomachOnlycolor" : 13,
  "innerEarOnlycolor" : 15,
  "markingsOnlycolor" : 20,
  "animation" :  1,
}

var britishDNA = {
  "headcolor" : 19,
  "pawcolor" : 19,
  "markingcolor" : 20,
  "snoutcolor" : 18,
  "eyecolor" : 40,
  //Cattributes
  "eyesShape" : 2,
  "decorationOnOff" : 2,
  "snoutStyle": 4,
  "snoutOnlycolor" : 18,
  "stomachOnlycolor" : 18,
  "innerEarOnlycolor" : 18,
  "markingsOnlycolor" : 20,
  "animation" :  1,
}

// when page load
$( document ).ready(function() {
    $('#dnabody').html(defaultDNA.headcolor);
    $('#dnapaw').html(defaultDNA.pawcolor);
    $('#dnamarking').html(defaultDNA.markingcolor);
    $('#dnasnout').html(defaultDNA.snoutcolor);
    $('#dnaeye').html(defaultDNA.eyecolor);
    $('#dnashape').html(defaultDNA.eyesShape)
    $('#dnadecoration').html(defaultDNA.decorationPattern)
    $('#dnasnouttype').html(defaultDNA.snoutStyle)
    $('#dnasnoutOnly').html(defaultDNA.snoutOnlycolor)
    $('#dnastomachOnly').html(defaultDNA.stomachOnlycolor)
    $('#dnainnerEarOnly').html(defaultDNA.innerEarOnlycolor)
    $('#dnamarkingsOnly').html(defaultDNA.markingsOnlycolor)
    $('#dnaanimation').html(defaultDNA.animation)
    $('#dnaspecial').html(defaultDNA.lastNum)

    renderCat(defaultDNA)
});

function getDna(){
    var dna = ''
    dna += $('#dnabody').html()
    dna += $('#dnapaw').html()
    dna += $('#dnamarking').html()
    dna += $('#dnasnout').html()
    dna += $('#dnaeye').html()
    dna += $('#dnashape').html()
    dna += $('#dnadecoration').html()
    dna += $('#dnasnouttype').html()
    dna += $('#dnasnoutOnly').html()
    dna += $('#dnastomachOnly').html()
    dna += $('#dnainnerEarOnly').html()
    dna += $('#dnamarkingsOnly').html()
    dna += $('#dnaanimation').html()
    dna += $('#dnaspecial').html()

    return parseInt(dna)
}

function renderCat(dna){

    //Color Groups
    headColor(colors[dna.headcolor],dna.headcolor)
    $('#bodycolor').val(dna.headcolor)

    pawColor(colors[dna.pawcolor],dna.pawcolor)
    $('#pawcolor').val(dna.pawcolor)

    markingColor(colors[dna.markingcolor],dna.markingcolor)
    $('#markingcolor').val(dna.markingcolor)

    snoutColor(colors[dna.snoutcolor],dna.snoutcolor)
    $('#snoutcolor').val(dna.snoutcolor)

    eyeColor(colors[dna.eyecolor],dna.eyecolor)
    $('#eyecolor').val(dna.eyecolor)

    //Cattributes
    eyeVariation(dna.eyesShape)
    $('#eyeshape').val(dna.eyesShape)

    decorationVariation(dna.decorationOnOff)
    $('#markingsOnOff').val(dna.decorationOnOff)

    snoutVariation(dna.snoutStyle)
    $('#snoutType').val(dna.snoutStyle)


    //Animation
    animationVariation(dna.animation)
    $('#animationType').val(dna.animation)


    //Individual colors
    snoutOnlyColor(colors[dna.snoutOnlycolor],dna.snoutOnlycolor)
    $('#snoutOnlycolor').val(dna.snoutOnlycolor)

    stomachOnlyColor(colors[dna.stomachOnlycolor],dna.stomachOnlycolor)
    $('#stomachOnlycolor').val(dna.stomachOnlycolor)

    innerEarOnlyColor(colors[dna.innerEarOnlycolor],dna.innerEarOnlycolor)
    $('#innerEarOnlycolor').val(dna.innerEarOnlycolor)

    markingsOnlyColor(colors[dna.markingsOnlycolor],dna.markingsOnlycolor)
    $('#markingsOnlycolor').val(dna.markingsOnlycolor)

    //hide attributes initial render
    $('#attributes-group').hide();
}



// Changing cat colors
$('#bodycolor').change(()=>{
    var colorVal = $('#bodycolor').val()
    headColor(colors[colorVal],colorVal)
})
$('#pawcolor').change(()=>{
  var colorVal = $('#pawcolor').val()
  pawColor(colors[colorVal],colorVal)
})
$('#markingcolor').change(()=>{
  var colorVal = $('#markingcolor').val()
  markingColor(colors[colorVal],colorVal)
})
$('#snoutcolor').change(()=>{
  var colorVal = $('#snoutcolor').val()
  snoutColor(colors[colorVal],colorVal)
})
$('#eyecolor').change(()=>{
  var colorVal = $('#eyecolor').val()
  eyeColor(colors[colorVal],colorVal)
})

//style changes
$('#eyeshape').change(()=>{
  var shape = parseInt($('#eyeshape').val()) //value from slider (1 to 7)
  eyeVariation(shape)
})

$('#markingsOnOff').change(()=>{
  var shape = parseInt($('#markingsOnOff').val()) //value from slider (1 to 7)
  decorationVariation(shape)
})

$('#snoutType').change(()=>{
  var shape = parseInt($('#snoutType').val()) //value from slider (1 to 7)
  snoutVariation(shape)
})

//animations
$('#animationType').change(()=>{
  var animationVal = parseInt($('#animationType').val()) //value from slider (1 to 7)
  animationVariation(animationVal)
})



//individual color changes
$('#snoutOnlycolor').change(()=>{
  var colorVal = $('#snoutOnlycolor').val()
  snoutOnlyColor(colors[colorVal],colorVal)
})

$('#stomachOnlycolor').change(()=>{
  var colorVal = $('#stomachOnlycolor').val()
  stomachOnlyColor(colors[colorVal],colorVal)
})

$('#innerEarOnlycolor').change(()=>{
  var colorVal = $('#innerEarOnlycolor').val()
  innerEarOnlyColor(colors[colorVal],colorVal)
})

$('#markingsOnlycolor').change(()=>{
  var colorVal = $('#markingsOnlycolor').val()
  markingsOnlyColor(colors[colorVal],colorVal)
})

//Show/hide tab groups

$(".btn.colors").ready(()=>{
  $(".tab.colors").css('display', 'block');
  $(".tab.colors2").css('display', 'none');
})
$(".btn.colors").click(()=>{
  $(".tab.colors").css('display', 'block');
  $(".tab.colors2").css('display', 'none');
})
$(".btn.colors2").click(()=>{
  $(".tab.colors").css('display', 'none');
  $(".tab.colors2").css('display', 'block');
})

//functional Buttons
$(".btn.tabby").click(() => {
  renderCat(defaultDNA)
})

$(".btn.burmese").click(() => {
  renderCat(burmeseDNA)
  $('.cat').find('span2').css('background', 'transparent')
})

$(".btn.tuxedo").click(() => {
  renderCat(tuxedoDNA)
  $('.cat').find('span2').css('background', 'transparent')
  $('.cat').find('span3').css('background', 'transparent')
})

$(".btn.british").click(() => {
  renderCat(britishDNA)
  $('.cat').find('span2').css('background', 'transparent')
})
$(".btn.random").click(() => {
  var randomDNA = {
    "headcolor" : Math.floor(Math.random() * 89) + 10,
    "pawcolor" : Math.floor(Math.random() * 89) + 10,
    "markingcolor" : Math.floor(Math.random() * 89) + 10,
    "snoutcolor" : Math.floor(Math.random() * 89) + 10,
    "eyecolor" : Math.floor(Math.random() * 89) + 10,
    //Cattributes
    "eyesShape" : Math.floor(Math.random() * 3) + 1,
    "decorationOnOff" : Math.floor(Math.random() * 3) + 1,
    "snoutStyle": Math.floor(Math.random() * 4) + 1,
    "snoutOnlycolor" : Math.floor(Math.random() * 89) + 10,
    "stomachOnlycolor" : Math.floor(Math.random() * 89) + 10,
    "innerEarOnlycolor" : Math.floor(Math.random() * 89) + 10,
    "markingsOnlycolor" : Math.floor(Math.random() * 89) + 10,
    "animation" : Math.floor(Math.random() * 4) + 1,
  //    "lastNum" :  1
    }

    $('#dnabody').html(defaultDNA.headcolor);
    $('#dnapaw').html(defaultDNA.pawcolor);
    $('#dnamarking').html(defaultDNA.markingcolor);
    $('#dnasnout').html(defaultDNA.snoutcolor);
    $('#dnaeye').html(defaultDNA.eyecolor);
    $('#dnashape').html(defaultDNA.eyesShape)
    $('#dnadecoration').html(defaultDNA.decorationPattern)
    $('#dnasnouttype').html(defaultDNA.snoutStyle)
    $('#dnasnoutOnly').html(defaultDNA.snoutOnlycolor)
    $('#dnastomachOnly').html(defaultDNA.stomachOnlycolor)
    $('#dnainnerEarOnly').html(defaultDNA.innerEarOnlycolor)
    $('#dnamarkingsOnly').html(defaultDNA.markingsOnlycolor)
    $('#dnaanimation').html(defaultDNA.animation)
    $('#dnaspecial').html(defaultDNA.lastNum)

    renderCat(randomDNA)
})

CatFactory

//Random color
function getColor() {
    var randomColor = Math.floor(Math.random() * 16777215).toString(16);
    return randomColor
}

function genColors(){
    var colors = []
    for(var i = 10; i < 99; i ++){
      var color = getColor()
      colors[i] = color
    }
    return colors
}

//This function code needs to modified so that it works with Your cat code.
function headColor(color,code) {
    $('.head, .chest').css('background', '#' + color)  //This changes the color of the cat
    $('#headcode').html(code) //This updates text of the badge next to the slider
    $('#dnabody').html(code) //This updates the body color part of the DNA that is displayed below the cat
}
function pawColor(color,code) {
    $('.paw_front_left, .paw_front_right, .paw_back_right, .paw_back_left, .tail, .ear').css('background', '#' + color)  //This changes the color of the cat
    $('#pawcode').html(code) //This updates text of the badge next to the slider
    $('#dnapaw').html(code) //This updates the body color part of the DNA that is displayed below the cat
}
function markingColor(color,code) {
    $('.forehead_markings_middle, .forehead_markings_left, .forehead_markings_right, .paw_stripe, .bottom_stripe, .tail_marking, .inner_ear').css('background', '#' + color)  //This changes the color of the cat
    $('#markingcode').html(code) //This updates text of the badge next to the slider
    $('#dnamarking').html(code) //This updates the body color part of the DNA that is displayed below the cat
}
function snoutColor(color,code) {
    $('.snout, .stomach').css('background', '#' + color)  //This changes the color of the cat
    $('#snoutcode').html(code) //This updates text of the badge next to the slider
    $('#dnasnout').html(code) //This updates the body color part of the DNA that is displayed below the cat
}
function eyeColor(color,code) {
    $('.irus').css('background', '#' + color)  //This changes the color of the cat
    $('#eyecode').html(code) //This updates text of the badge next to the slider
    $('#dnaeye').html(code) //This updates the body color part of the DNA that is displayed below the cat
}

//Cattributes
function snoutOnlyColor(color,code) {
    $('.snout').css('background', '#' + color)  //This changes the color of the cat
    $('#snoutOnlycode').html(code) //This updates text of the badge next to the slider
    $('#dnasnoutOnly').html(code) //This updates the body color part of the DNA that is displayed below the cat
}
function stomachOnlyColor(color,code) {
    $('.stomach').css('background', '#' + color)  //This changes the color of the cat
    $('#stomachOnlycode').html(code) //This updates text of the badge next to the slider
    $('#dnastomachOnly').html(code) //This updates the body color part of the DNA that is displayed below the cat
}
function innerEarOnlyColor(color,code) {
    $('.inner_ear').css('background', '#' + color)  //This changes the color of the cat
    $('#innerEarOnlycode').html(code) //This updates text of the badge next to the slider
    $('#dnainnerEarOnly').html(code) //This updates the body color part of the DNA that is displayed below the cat
}
function markingsOnlyColor(color,code) {
    $('.forehead_markings_middle, .forehead_markings_left, .forehead_markings_right, .paw_stripe, .bottom_stripe, .tail_marking').css('background', '#' + color)  //This changes the color of the cat
    $('#markingsOnlycode').html(code) //This updates text of the badge next to the slider
    $('#dnamarkingsOnly').html(code) //This updates the body color part of the DNA that is displayed below the cat
}

//###################################################
//Functions below will be used later on in the project
//###################################################
function eyeVariation(num) {

    $('#dnashape').html(num)
    switch (num) {
        case 1:
            normalEyes()
            $('#eyename').html('None')
            break
        case 2: 
            normalEyes() // reset
            $('#eyename').html('Day') // set badge to "Chill"
            eyesType1() //Set border to change the shape of the eye
            break
        case 3: 
            normalEyes() // reset
            $('#eyename').html('Night') // set badge to "Chill"
            eyesType2() //Set border to change the shape of the eye
            break
        default:
            console.log("Not 1, 2 or 3")
            break

    }
}

function decorationVariation(num) {

    $('#dnadecoration').html(num)
    switch (num) {
        case 1:
            normaldecoration()
            $('#markingsName').html('Tabby')
            console.log(num)
            break
        case 2: 
            normaldecoration() // reset
            $('#markingsName').html('None')
            nodecoration()
            console.log(num)
            break
        case 3: 
            normaldecoration() // reset
            $('#markingsName').html('Tabby')
            normaldecoration()
            console.log(num)
            break            
    }
}

function snoutVariation(num) {

    $('#dnasnouttype').html(num)
    switch (num) {
        case 1:
            normalSnout()
            $('#snoutName').html('Normal')
            break
        case 2: 
            normalSnout() // reset
            $('#snoutName').html('Burmese') // set badge to "Chill"
            burmeseSnout() //Set border to change the shape of the eye
            break
        case 3: 
            normalSnout() // reset
            $('#snoutName').html('Tuxedo') // set badge to "Chill"
            tuxedoSnout() //Set border to change the shape of the eye
            break
        case 4: 
            normalSnout() // reset
            $('#snoutName').html('British Shorthair') // set badge to "Chill"
            unicolorSnout() //Set border to change the shape of the eye
            break
    }
}

function animationVariation(num) {

    $('#dnaanimation').html(num)
    switch (num) {
        case 1:
            $('#animationName').html('None')
            noAnimation()
            break
        case 2: 
            earAnimation()
            $('#animationName').html('Ear') // set badge
            break
        case 3: 
            $('#animationName').html('Whiskers') // set badge to "Chill"
            whiskersAnimation() //Set border to change the shape of the eye
            break
        case 4: 
            $('#animationName').html('Tail') // set badge to "Chill"
            tailAnimation() //Set border to change the shape of the eye
            break
    }
}

function normalEyes() {
     $('.eyes').find('span').css('background', 'transparent')
}
function eyesType1() {
     $('.eyes').find('span').css({'background': '#18331d', 'width': '7px', 'left': '13px'})
}
function eyesType2() {
    $('.eyes').find('span').css({'background': '#18331d', 'width': '15px', 'left': '9px'})
}

function normaldecoration() {
    $('.cat').find('span2').css('background', '#d7c3a3')
}
function nodecoration() {
    $('.cat').find('span2').css('background', 'transparent')
}

function normalSnout() {
    $('.cat').find('span3').css({
        'background': '#fff3e0',
        'width': '132px', 
        'height': '64px', 
        'margin-top': '61px',
        'margin-left': '40px',
        'border-bottom': '0px solid transparent', 
        'border-left': '0px solid transparent', 
        'border-right': '0px solid transparent',
        'border-radius': '55% 55% 60% 60%',
})
}
function unicolorSnout() {
    $('.cat').find('span3').css({
        'background': '#fff3e0',
        'width': '51px', 
        'height': '44px', 
        'margin-top': '63px',
        'margin-left': '81px',
        'border-bottom': '0px solid transparent', 
        'border-left': '0px solid transparent', 
        'border-right': '0px solid transparent',
        'border-radius': '55% 55% 60% 60%',
})
}
function burmeseSnout() {
    $('.cat').find('span3').css({'width': '171px', 'height': '132px', 'margin-top': '-9px','margin-left': '21px'})
}
function tuxedoSnout() {
    $('.cat').find('span3').css({
        'background': 'transparent',
        'width': '0', 
        'height': '0', 
        'margin-top': '10px',
        'margin-left': '7px',
        'border-bottom': '120px solid #fff3e0', 
        'border-left': '100px solid transparent', 
        'border-right': '100px solid transparent',
        'border-radius': '50% 50% 50% 50%',
    })
}

function noAnimation() {
    resetAnimation()
}

function earAnimation() {
    resetAnimation()
    $('#left_ear').addClass("movingEar_left")
}

function whiskersAnimation() {
    resetAnimation()
    $("#whisker_mid_left").addClass('movingWhiskers_mid_left')
    $("#whisker_top_left").addClass('movingWhiskers_top_left')
    $("#whisker_bottom_left").addClass('movingWhiskers_bottom_left')
    $("#whisker_mid_right").addClass('movingWhiskers_mid_right')
    $("#whisker_top_right").addClass('movingWhiskers_top_right')
    $("#whisker_bottom_right").addClass('movingWhiskers_bottom_right')
}

function tailAnimation() {
    resetAnimation()
    $("#tail").addClass("movingTail")
}

function resetAnimation() {
    $("#left_ear").removeClass('movingEar_left')
    $("#tail").removeClass('movingTail')
    $("#whisker_mid_left").removeClass('movingWhiskers_mid_left')
    $("#whisker_top_left").removeClass('movingWhiskers_top_left')
    $("#whisker_bottom_left").removeClass('movingWhiskers_bottom_left')
    $("#whisker_mid_right").removeClass('movingWhiskers_mid_right')
    $("#whisker_top_right").removeClass('movingWhiskers_top_right')
    $("#whisker_bottom_right").removeClass('movingWhiskers_bottom_right')
}

/*async function normaldecoration() {
    //Remove all style from other decorations
    //In this way we can also use normalDecoration() to reset the decoration style
    $('.cat__head-dots').css({ "transform": "rotate(0deg)", "height": "48px", "width": "14px", "top": "1px", "border-radius": "0 0 50% 50%" })
    $('.cat__head-dots_first').css({ "transform": "rotate(0deg)", "height": "35px", "width": "14px", "top": "1px", "border-radius": "50% 0 50% 50%" })
    $('.cat__head-dots_second').css({ "transform": "rotate(0deg)", "height": "35px", "width": "14px", "top": "1px", "border-radius": "0 50% 50% 50%" })
}*/

2 Likes