Explore all Code Quality open source software, libraries, packages, source code, cloud functions and APIs.

Popular New Releases in Code Quality

prettier

2.6.2

ReflectionDocBlock

5.3.0

PhoneNumberKit

PhoneNumberKit 3.3.5

ohm

Ohm v16.3.1

grumphp

Version 1.9.0

Popular Libraries in Code Quality

prettier

by prettier doticonjavascriptdoticon

star image 42446 doticonMIT

Prettier is an opinionated code formatter.

yapf

by google doticonpythondoticon

star image 11947 doticonApache-2.0

A formatter for Python files

ReflectionDocBlock

by phpDocumentor doticonphpdoticon

star image 8973 doticonMIT

Numeral-js

by adamwdraper doticonjavascriptdoticon

star image 8867 doticonMIT

A javascript library for formatting and manipulating numbers.

languagetool

by languagetool-org doticonjavadoticon

star image 6461 doticonLGPL-2.1

Style and Grammar Checker for 25+ Languages

PhoneNumberKit

by marmelroy doticonswiftdoticon

star image 4481 doticonMIT

A Swift framework for parsing, formatting and validating international phone numbers. Inspired by Google's libphonenumber.

ohm

by harc doticonjavascriptdoticon

star image 4143 doticonMIT

A library and language for building parsers, interpreters, compilers, etc.

better-exceptions

by Qix- doticonpythondoticon

star image 3959 doticonMIT

Pretty and useful exceptions in Python, automatically.

grumphp

by phpro doticonphpdoticon

star image 3730 doticonMIT

A PHP code-quality tool

Trending New libraries in Code Quality

interrogate

by econchick doticonpythondoticon

star image 348 doticonMIT

Explain yourself! Interrogate a codebase for docstring coverage.

currency

by bojanz doticongodoticon

star image 284 doticonMIT

Currency handling for Go.

djhtml

by rtts doticonpythondoticon

star image 281 doticonGPL-3.0

Django/Jinja template indenter

nautilus

by nautilus-fuzz doticonpythondoticon

star image 245 doticonAGPL-3.0

A grammar based feedback Fuzzer

cargo-spellcheck

by drahnr doticonrustdoticon

star image 240 doticonNOASSERTION

Checks all your documentation for spelling and grammar mistakes with hunspell and a nlprule based checker for grammar

csharpier

by belav doticoncsharpdoticon

star image 231 doticonMIT

CSharpier is an opinionated code formatter for c#.

language_tool_python

by jxmorris12 doticonpythondoticon

star image 199 doticonGPL-3.0

a free python grammar checker 📝✅

complexity

by thoughtbot doticonrustdoticon

star image 108 doticonMIT

A command line tool to identify complex code

template-jsx

by blaumeise20 doticontypescriptdoticon

star image 101 doticonMIT

Template rendering engine for JSX

Top Authors in Code Quality

1

Unibeautify

8 Libraries

star icon525

2

codacy

5 Libraries

star icon101

3

microsoft

4 Libraries

star icon1056

4

prettier

4 Libraries

star icon45423

5

myint

4 Libraries

star icon618

6

atom

3 Libraries

star icon170

7

sourcegraph

3 Libraries

star icon363

8

umpirsky

3 Libraries

star icon882

9

jonschlinkert

3 Libraries

star icon129

10

open-orchestra

3 Libraries

star icon6

1

8 Libraries

star icon525

2

5 Libraries

star icon101

3

4 Libraries

star icon1056

4

4 Libraries

star icon45423

5

4 Libraries

star icon618

6

3 Libraries

star icon170

7

3 Libraries

star icon363

8

3 Libraries

star icon882

9

3 Libraries

star icon129

10

3 Libraries

star icon6

Trending Kits in Code Quality

No Trending Kits are available at this moment for Code Quality

Trending Discussions on Code Quality

Run the command in Linux machine, just the same way batch is used in Windows machine

Use of Deprecated PMD rules

How do I specify a specific prettier version in a VSCode .devcontainer?

Circular Dependency Error when using Enumerations

Text based JavaScript Ajax quiz

Exposed ORM: DSL vs DAO in Many-to many relationships best practices

How do I output only a capture group with sed

CodeClimate Not reading configuration

Rust compiler not optimising lzcnt? (and similar functions)

Gitlab-CI: Nodejs application fails to build

QUESTION

Run the command in Linux machine, just the same way batch is used in Windows machine

Asked 2022-Mar-22 at 09:57

I am new to linux System, there was scenario where through my Jenkinsfile I have to run the command bat 'mvn sonar:sonar -Dsonar.projectKey=testproject -Dsonar.host.url=https://localhostxy.com -Dsonar.login=xyzloginid'on linux machine, but getting an error as I was using batch.

The same batch command is working on window based machine.

Please suggest me an alternate way to run it on Linux based machine.

Jenkinsfile stage as below, its working on Windows, please suggest the changes to make it work on linux based machine.

1stage('SonarQube Code QualityCheck') {
2        steps {           
3            bat 'mvn sonar:sonar -Dsonar.projectKey=testproject -Dsonar.host.url=https://localhostxy.com -Dsonar.login=xyzloginid'            
4            }
5     }
6

Thanks in advance for the help.

ANSWER

Answered 2022-Mar-22 at 09:57

Here is the solution:

1stage('SonarQube Code QualityCheck') {
2        steps {           
3            bat 'mvn sonar:sonar -Dsonar.projectKey=testproject -Dsonar.host.url=https://localhostxy.com -Dsonar.login=xyzloginid'            
4            }
5     }
6stage('SonarQube Code QualityCheck') {
7  steps {           
8    sh 'mvn sonar:sonar -Dsonar.projectKey=testproject -Dsonar.host.url=https://localhostxy.com -Dsonar.login=xyzloginid'            
9  }
10}
11

Source https://stackoverflow.com/questions/71569981

QUESTION

Use of Deprecated PMD rules

Asked 2022-Feb-17 at 12:52

We've recently picked up PMD on our Salesforce project to help with our Apex code quality analysis. We've implemented a couple of rules, but have seen that most of the really valuable-looking rules (around performance, complexity, etc) are marked as deprecated.

Do people generally use continue to use deprecated rules (as they still work, even if they are no longer actively supported)? Or does deprecated in this sense mean that these may be broken/unreliable.

Does the prevalence of deprecated PMD rules mean that we should be looking for an alternative tool?

I'd really welcome your thoughts

ANSWER

Answered 2022-Feb-17 at 12:52

There are very few deprecated rules in the Apex module: https://pmd.github.io/latest/pmd_rules_apex.html

PMD rules are usually not deprecated without a replacement. For instance AvoidDmlStatementsInLoops is replaced by OperationWithLimitsInLoops, as documented. Sometimes several rules are consolidated into a single one, which is the case for those 3 performance rules. You might get the impression that many rules are deprecated, but no functionality is lost, and the newer rules are generally more easily extensible.

If you are seeing many deprecation warnings, it may be because you are referencing those rules through deprecated rulesets. For instance, if you write

1  <rule ref="rulesets/apex/complexity.xml/AvoidDeeplyNestedIfStmts" />
2

you will get a deprecation warning, as the ruleset will be removed in PMD 7. However, the rule is not deprecated, and is still accessible at

1  <rule ref="rulesets/apex/complexity.xml/AvoidDeeplyNestedIfStmts" />
2  <rule ref="category/apex/design.xml/AvoidDeeplyNestedIfStmts" />
3

I'm suggesting this because you mention deprecated complexity rules, and no complexity rules of PMD Apex are deprecated (the ruleset complexity.xml is though).

In PMD 6, PMD's rule library has been reorganized into "categories", in contrast with the previous approach of publishing rulesets directly. Consequently, most built-in rulesets have been deprecated until PMD 7, which does not mean the rules themselves are deprecated.

Source https://stackoverflow.com/questions/71125281

QUESTION

How do I specify a specific prettier version in a VSCode .devcontainer?

Asked 2022-Feb-02 at 17:28
Background

In a repo, we have a pre-commit configuration that requires version 2.2.1 of prettier:

1  - repo: https://github.com/pre-commit/mirrors-prettier
2    rev: "v2.2.1"
3    hooks:
4      - id: prettier
5

And in my .devcontainer I specify use of prettier, so that my code gets formatted on save:

1  - repo: https://github.com/pre-commit/mirrors-prettier
2    rev: "v2.2.1"
3    hooks:
4      - id: prettier
5{
6  // ...
7  "settings": {
8    "editor.formatOnSave": true,
9    "editor.defaultFormatter": "esbenp.prettier-vscode"
10    // ...
11  }
12}
13

Prettier is installed by the vscode extension, not globally, so doing:

1  - repo: https://github.com/pre-commit/mirrors-prettier
2    rev: "v2.2.1"
3    hooks:
4      - id: prettier
5{
6  // ...
7  "settings": {
8    "editor.formatOnSave": true,
9    "editor.defaultFormatter": "esbenp.prettier-vscode"
10    // ...
11  }
12}
13npm list -g | grep prettier
14

in my dev container doesn't list anything installed.

The problem

A different version of prettier is being used, and I get a conflict in how it formats arrays in json files. Every time I open up a particular json file, it gets reformatted by my editor.

Also, if I rebuild my devcontainer, I'm then liable to unknowingly switch the version of code formatter I use, leading to git hell.

The question

How can I specify that my devcontainer use an exact prettier version so I can enforce the same behaviour in my dev environment as in our code quality tools?

I have already tried this:

You can set up the prettier extension to use a resolved version of prettier, according to the instructions under "Prettier Resolution" here.

So I added to the Dockerfile:

1  - repo: https://github.com/pre-commit/mirrors-prettier
2    rev: "v2.2.1"
3    hooks:
4      - id: prettier
5{
6  // ...
7  "settings": {
8    "editor.formatOnSave": true,
9    "editor.defaultFormatter": "esbenp.prettier-vscode"
10    // ...
11  }
12}
13npm list -g | grep prettier
14# Ensure prettier is installed globally so the esbenp.prettier-vscode can find a specific version
15# as discussed here:
16#   https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
17# NB You can remove the -g flag if you have a node project. I install globally because I use prettier on all projects, whether they have a node_modules folder or not.
18RUN npm install prettier@2.2.1 -g -D --save-exact
19

And in the .devcontainer.json settings, told the extension to resolve the prettier module instead of using its own:

1  - repo: https://github.com/pre-commit/mirrors-prettier
2    rev: "v2.2.1"
3    hooks:
4      - id: prettier
5{
6  // ...
7  "settings": {
8    "editor.formatOnSave": true,
9    "editor.defaultFormatter": "esbenp.prettier-vscode"
10    // ...
11  }
12}
13npm list -g | grep prettier
14# Ensure prettier is installed globally so the esbenp.prettier-vscode can find a specific version
15# as discussed here:
16#   https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
17# NB You can remove the -g flag if you have a node project. I install globally because I use prettier on all projects, whether they have a node_modules folder or not.
18RUN npm install prettier@2.2.1 -g -D --save-exact
19{
20  // ...
21  "settings": {
22    "editor.formatOnSave": true,
23    "editor.defaultFormatter": "esbenp.prettier-vscode",
24    "prettier.resolveGlobalModules": true,
25    // ...
26  }
27}
28

That didn't work so I also tried adding:

1  - repo: https://github.com/pre-commit/mirrors-prettier
2    rev: "v2.2.1"
3    hooks:
4      - id: prettier
5{
6  // ...
7  "settings": {
8    "editor.formatOnSave": true,
9    "editor.defaultFormatter": "esbenp.prettier-vscode"
10    // ...
11  }
12}
13npm list -g | grep prettier
14# Ensure prettier is installed globally so the esbenp.prettier-vscode can find a specific version
15# as discussed here:
16#   https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
17# NB You can remove the -g flag if you have a node project. I install globally because I use prettier on all projects, whether they have a node_modules folder or not.
18RUN npm install prettier@2.2.1 -g -D --save-exact
19{
20  // ...
21  "settings": {
22    "editor.formatOnSave": true,
23    "editor.defaultFormatter": "esbenp.prettier-vscode",
24    "prettier.resolveGlobalModules": true,
25    // ...
26  }
27}
28    "prettier.prettierPath": "$(npm root -g)/prettier",
29

Which also didn't work; the prettier extension is still using it's own version.

ANSWER

Answered 2022-Feb-02 at 17:28

You can set the version in the .devcontainer like this:

1  - repo: https://github.com/pre-commit/mirrors-prettier
2    rev: "v2.2.1"
3    hooks:
4      - id: prettier
5{
6  // ...
7  "settings": {
8    "editor.formatOnSave": true,
9    "editor.defaultFormatter": "esbenp.prettier-vscode"
10    // ...
11  }
12}
13npm list -g | grep prettier
14# Ensure prettier is installed globally so the esbenp.prettier-vscode can find a specific version
15# as discussed here:
16#   https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
17# NB You can remove the -g flag if you have a node project. I install globally because I use prettier on all projects, whether they have a node_modules folder or not.
18RUN npm install prettier@2.2.1 -g -D --save-exact
19{
20  // ...
21  "settings": {
22    "editor.formatOnSave": true,
23    "editor.defaultFormatter": "esbenp.prettier-vscode",
24    "prettier.resolveGlobalModules": true,
25    // ...
26  }
27}
28    "prettier.prettierPath": "$(npm root -g)/prettier",
29"extensions": ["esbenp.prettier-vscode@8.0.1"],
30

The trick is you also have to turn off extension automatic updates:

1  - repo: https://github.com/pre-commit/mirrors-prettier
2    rev: "v2.2.1"
3    hooks:
4      - id: prettier
5{
6  // ...
7  "settings": {
8    "editor.formatOnSave": true,
9    "editor.defaultFormatter": "esbenp.prettier-vscode"
10    // ...
11  }
12}
13npm list -g | grep prettier
14# Ensure prettier is installed globally so the esbenp.prettier-vscode can find a specific version
15# as discussed here:
16#   https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
17# NB You can remove the -g flag if you have a node project. I install globally because I use prettier on all projects, whether they have a node_modules folder or not.
18RUN npm install prettier@2.2.1 -g -D --save-exact
19{
20  // ...
21  "settings": {
22    "editor.formatOnSave": true,
23    "editor.defaultFormatter": "esbenp.prettier-vscode",
24    "prettier.resolveGlobalModules": true,
25    // ...
26  }
27}
28    "prettier.prettierPath": "$(npm root -g)/prettier",
29"extensions": ["esbenp.prettier-vscode@8.0.1"],
30"settings": {
31    "extensions.autoCheckUpdates": false,
32    "extensions.autoUpdate": false
33},
34

Note: This turns off automatic updates for all extensions.

Also, RUN npm install prettier@2.2.1 -g -D --save-exact in the Dockerfile adds the prettier CLI to the environment, not the VS Code extension.

Source https://stackoverflow.com/questions/69449987

QUESTION

Circular Dependency Error when using Enumerations

Asked 2022-Feb-02 at 04:27

I want to assign certain time weightage values to the variables of a data set. So I am trying to use Enumerations/Constants so to improve my code quality and make it easy to maintain. But on compiling my project, it throws in a Circular Dependencies Between Modules error.

What I have understood is, one is allowed to use only constants [Eg: 2,3.14,56....], in the truest sense of the word. Bottom line, if I can't use Either Enumerations or Constants. Then how can I achieve my objective of keeping my weightages code-block, in a way that any changes in them is reflected everywhere in my project than me having to do a find and update manually every instance.

What I am getting at, is to have a global variable that can be accessed throughout the project and is dynamic.

1Private Const Wtage As Double = ConvTohr(34) 'Error happens here
2
3Enum Weightage
4   Var1_Weightage = ConvTohr(3)  'Error happens here
5   Var2_Weightage = ConvTohr(11)
6   Var3_Weightage = ConvTohr(2)
7   var4_Weightage = ConvTohr(9)
8   var5_Weightage = ConvTohr(0)
9End Enum
10
11Private Function ConvTohr(val As Integer) As Double
12    If val = 0 Then
13       ConvTohr = 0
14       Exit Function
15    End If
16    ConvTohr = Round((val / 60), 2)
17End Function
18

Error Snap

ANSWER

Answered 2022-Feb-02 at 04:27
  • The error message is incorrect: your code does not have any circular references.
    • This is more of a bug in the VBA interpreter: your code is still incorrect and invalid, but VBA is showing the wrong error message.
    • Given that VBA remains effectively frozen-in-time since 2002 (excepting 64-bit support in 2007), so don't expect any fixes, let alone any enhancements, ever (Though MS Office's COM automation tooling is slowly shifting to JavaScript (maybe Python? please?).
  • The actual problem with your code is threefold:
    • You cannot use a Function to initialize a Const value in VBA.
    • You cannot use a Function to define values for a VBA Enum either.
    • You cannot have Enum members typed as Double: VBA only supports Integer and Long values for Enum members.
      • Curiously, VBA does allow Const values to be typed as Double - but most other languages don't because Double is an IEEE-754 floating point type that does not have a machine-portable representation, but as VBA is only for Win32 on x86/x64 I guess that means Microsoft made it work given the very narrow gamut of hardware that VBA programs will run on.

Anyway, if you want "named values" typed as Double that you can use anywhere, then try this:

  1. Create a new Module (not a Class Module).

  2. Rename the Module from Module1 to Weightage.

  3. Put this code in Weightage:

1Private Const Wtage As Double = ConvTohr(34) 'Error happens here
2
3Enum Weightage
4   Var1_Weightage = ConvTohr(3)  'Error happens here
5   Var2_Weightage = ConvTohr(11)
6   Var3_Weightage = ConvTohr(2)
7   var4_Weightage = ConvTohr(9)
8   var5_Weightage = ConvTohr(0)
9End Enum
10
11Private Function ConvTohr(val As Integer) As Double
12    If val = 0 Then
13       ConvTohr = 0
14       Exit Function
15    End If
16    ConvTohr = Round((val / 60), 2)
17End Function
18Private Function ConvTohr(val As Integer) As Double
19    ConvTohr = Round((val / 60), 2)
20End Function
21
22Public Property Get Var1_Weightage() As Double
23    Var1_Weightage = ConvTohr(3)
24End Property
25Public Property Get Var2_Weightage() As Double
26    Var2_Weightage = ConvTohr(11)
27End Property
28Public Property Get Var3_Weightage() As Double
29    Var3_Weightage = ConvTohr(2)
30End Property
31Public Property Get Var4_Weightage() As Double
32    Var4_Weightage = ConvTohr(9)
33End Property
34Public Property Get Var5_Weightage() As Double
35    Var5_Weightage = ConvTohr(0)
36End Property
37
  • Screenshot proof:

    (See output in the Immediate pane):

    enter image description here

  • Source https://stackoverflow.com/questions/70937728

    QUESTION

    Text based JavaScript Ajax quiz

    Asked 2022-Jan-21 at 17:00

    I'm trying to create a text based quiz that moves on to the next slide when the correct answer is guessed. I have the code running(which is not showing questions in my pc but it is showing the questions perfectly here) but the input space is not displaying on my output screen. Can someone please help me identify the error?

    Base code is from https://codepen.io/SitePoint/pen/GmPjjL

    1(function(){
    2    // Functions
    3    function buildQuiz(){
    4      // variable to store the HTML output
    5      const output = [];
    6  
    7      // for each question...
    8      myQuestions.forEach(
    9        (currentQuestion, questionNumber) => {
    10  
    11          // variable to store the list of answers
    12          const answers = [];
    13
    14          for(questionNumber in currentQuestion.answers){
    15
    16        
    17            answers.push(
    18              `<label>
    19                <input type="text" name="question${questionNumber}" placeholder="Company" size="20">
    20              </label>`
    21              
    22            );
    23          }
    24  
    25          // add this question to the output
    26          output.push(
    27            `<div class="slide">
    28              <div class="question"> ${currentQuestion.question} </div>
    29            </div>`
    30          );
    31        }
    32      );
    33  
    34      // finally combine our output list into one string of HTML and put it on the page
    35      quizContainer.innerHTML = output.join('');
    36    }
    37  
    38    function showResults(){
    39  
    40      // gather answer containers from our quiz
    41      const answerContainers = quizContainer.querySelectorAll('.answers');
    42  
    43      // keep track of user's answers
    44      let numCorrect = 0;
    45  
    46      // for each question...
    47      myQuestions.forEach( (currentQuestion, questionNumber) => {
    48  
    49        // find selected answer
    50        const answerContainer = answerContainers[questionNumber];
    51        const userAnswer = (answerContainer.querySelector('input').value);
    52        
    53        //if answer is blank
    54    if (userAnswer.length === 0 ) {
    55        alert("You must enter an answer to continue...");
    56        return false;
    57    }
    58
    59        // if answer is correct
    60        if(userAnswer.toLowerCase() === currentQuestion.correctAnswer.toLowerCase()){
    61          // add to the number of correct answers
    62          numCorrect++;
    63  
    64          // alert
    65         alert("CONGRATULATIONS! Your answer is correct! You have advanced to the next level.");
    66        }
    67        // if answer is wrong
    68        else{
    69          // alert
    70          alert("Wrong answer, please, keep trying...");
    71        }
    72      });
    73  
    74      // show number of correct answers out of total
    75      resultsContainer.innerHTML = `${numCorrect} out of ${myQuestions.length}`;
    76    }
    77  
    78    function showSlide(n) {
    79      slides[currentSlide].classList.remove('active-slide');
    80      slides[n].classList.add('active-slide');
    81      currentSlide = n;
    82      if(currentSlide === 0){
    83        previousButton.style.display = 'none';
    84      }
    85      else{
    86        previousButton.style.display = 'inline-block';
    87      }
    88      if(currentSlide === slides.length-1){
    89        nextButton.style.display = 'none';
    90        submitButton.style.display = 'inline-block';
    91      }
    92      else{
    93        nextButton.style.display = 'inline-block';
    94        submitButton.style.display = 'none';
    95      }
    96    }
    97  
    98    function showNextSlide() {
    99      showSlide(currentSlide + 1);
    100    }
    101  
    102    function showPreviousSlide() {
    103      showSlide(currentSlide - 1);
    104    }
    105  
    106    // Variables
    107    const quizContainer = document.getElementById('quiz');
    108    const resultsContainer = document.getElementById('results');
    109    const submitButton = document.getElementById('submit');
    110    
    111    const myQuestions = [
    112    {
    113      question: "Who invented JavaScript?",
    114      image: "https://i.postimg.cc/rmRj3SYt/nikecw.png",
    115      answers: "Write your answer here",
    116      correctAnswer: "Nike",
    117    },
    118    {
    119      question: "Which one of these is a JavaScript package manager?",
    120      image: "https://i.postimg.cc/rmRj3SYt/nikecw.png",
    121      correctAnswer: "Nike",
    122
    123    },
    124    {
    125      question: "Which tool can you use to ensure code quality?",
    126      image: "https://i.postimg.cc/rmRj3SYt/nikecw.png",
    127      correctAnswer: "Nike",
    128    }
    129];
    130    // Kick things off
    131    buildQuiz();
    132  
    133    // Pagination
    134    const previousButton = document.getElementById("previous");
    135    const nextButton = document.getElementById("next");
    136    const slides = document.querySelectorAll(".slide");
    137    let currentSlide = 0;
    138  
    139    // Show the first slide
    140    showSlide(currentSlide);
    141  
    142    // Event listeners
    143    submitButton.addEventListener('click', showResults);
    144    previousButton.addEventListener("click", showPreviousSlide);
    145    nextButton.addEventListener("click", showNextSlide);
    146  })();
    147  
    1(function(){
    2    // Functions
    3    function buildQuiz(){
    4      // variable to store the HTML output
    5      const output = [];
    6  
    7      // for each question...
    8      myQuestions.forEach(
    9        (currentQuestion, questionNumber) => {
    10  
    11          // variable to store the list of answers
    12          const answers = [];
    13
    14          for(questionNumber in currentQuestion.answers){
    15
    16        
    17            answers.push(
    18              `<label>
    19                <input type="text" name="question${questionNumber}" placeholder="Company" size="20">
    20              </label>`
    21              
    22            );
    23          }
    24  
    25          // add this question to the output
    26          output.push(
    27            `<div class="slide">
    28              <div class="question"> ${currentQuestion.question} </div>
    29            </div>`
    30          );
    31        }
    32      );
    33  
    34      // finally combine our output list into one string of HTML and put it on the page
    35      quizContainer.innerHTML = output.join('');
    36    }
    37  
    38    function showResults(){
    39  
    40      // gather answer containers from our quiz
    41      const answerContainers = quizContainer.querySelectorAll('.answers');
    42  
    43      // keep track of user's answers
    44      let numCorrect = 0;
    45  
    46      // for each question...
    47      myQuestions.forEach( (currentQuestion, questionNumber) => {
    48  
    49        // find selected answer
    50        const answerContainer = answerContainers[questionNumber];
    51        const userAnswer = (answerContainer.querySelector('input').value);
    52        
    53        //if answer is blank
    54    if (userAnswer.length === 0 ) {
    55        alert("You must enter an answer to continue...");
    56        return false;
    57    }
    58
    59        // if answer is correct
    60        if(userAnswer.toLowerCase() === currentQuestion.correctAnswer.toLowerCase()){
    61          // add to the number of correct answers
    62          numCorrect++;
    63  
    64          // alert
    65         alert("CONGRATULATIONS! Your answer is correct! You have advanced to the next level.");
    66        }
    67        // if answer is wrong
    68        else{
    69          // alert
    70          alert("Wrong answer, please, keep trying...");
    71        }
    72      });
    73  
    74      // show number of correct answers out of total
    75      resultsContainer.innerHTML = `${numCorrect} out of ${myQuestions.length}`;
    76    }
    77  
    78    function showSlide(n) {
    79      slides[currentSlide].classList.remove('active-slide');
    80      slides[n].classList.add('active-slide');
    81      currentSlide = n;
    82      if(currentSlide === 0){
    83        previousButton.style.display = 'none';
    84      }
    85      else{
    86        previousButton.style.display = 'inline-block';
    87      }
    88      if(currentSlide === slides.length-1){
    89        nextButton.style.display = 'none';
    90        submitButton.style.display = 'inline-block';
    91      }
    92      else{
    93        nextButton.style.display = 'inline-block';
    94        submitButton.style.display = 'none';
    95      }
    96    }
    97  
    98    function showNextSlide() {
    99      showSlide(currentSlide + 1);
    100    }
    101  
    102    function showPreviousSlide() {
    103      showSlide(currentSlide - 1);
    104    }
    105  
    106    // Variables
    107    const quizContainer = document.getElementById('quiz');
    108    const resultsContainer = document.getElementById('results');
    109    const submitButton = document.getElementById('submit');
    110    
    111    const myQuestions = [
    112    {
    113      question: "Who invented JavaScript?",
    114      image: "https://i.postimg.cc/rmRj3SYt/nikecw.png",
    115      answers: "Write your answer here",
    116      correctAnswer: "Nike",
    117    },
    118    {
    119      question: "Which one of these is a JavaScript package manager?",
    120      image: "https://i.postimg.cc/rmRj3SYt/nikecw.png",
    121      correctAnswer: "Nike",
    122
    123    },
    124    {
    125      question: "Which tool can you use to ensure code quality?",
    126      image: "https://i.postimg.cc/rmRj3SYt/nikecw.png",
    127      correctAnswer: "Nike",
    128    }
    129];
    130    // Kick things off
    131    buildQuiz();
    132  
    133    // Pagination
    134    const previousButton = document.getElementById("previous");
    135    const nextButton = document.getElementById("next");
    136    const slides = document.querySelectorAll(".slide");
    137    let currentSlide = 0;
    138  
    139    // Show the first slide
    140    showSlide(currentSlide);
    141  
    142    // Event listeners
    143    submitButton.addEventListener('click', showResults);
    144    previousButton.addEventListener("click", showPreviousSlide);
    145    nextButton.addEventListener("click", showNextSlide);
    146  })();
    147  @import url(https://fonts.googleapis.com/css?family=Work+Sans:300,600);
    148
    149body{
    150    font-size: 20px;
    151    font-family: 'Work Sans', sans-serif;
    152    color: #333;
    153  font-weight: 300;
    154  text-align: center;
    155  background-color: #f8f6f0;
    156}
    157h1{
    158  font-weight: 300;
    159  margin: 0px;
    160  padding: 10px;
    161  font-size: 20px;
    162  background-color: #444;
    163  color: #fff;
    164}
    165.question{
    166  font-size: 30px;
    167  margin-bottom: 10px;
    168}
    169.answers {
    170  margin-bottom: 20px;
    171  text-align: left;
    172  display: inline-block;
    173}
    174.answers label{
    175  display: block;
    176  margin-bottom: 10px;
    177}
    178button{
    179  font-family: 'Work Sans', sans-serif;
    180    font-size: 22px;
    181    background-color: #279;
    182    color: #fff;
    183    border: 0px;
    184    border-radius: 3px;
    185    padding: 20px;
    186    cursor: pointer;
    187    margin-bottom: 20px;
    188}
    189button:hover{
    190    background-color: #38a;
    191}
    192
    193
    194
    195
    196
    197.slide{
    198  position: absolute;
    199  left: 0px;
    200  top: 0px;
    201  width: 100%;
    202  z-index: 1;
    203  opacity: 0;
    204  transition: opacity 0.5s;
    205}
    206.active-slide{
    207  opacity: 1;
    208  z-index: 2;
    209}
    210.quiz-container{
    211  position: relative;
    212  height: 200px;
    213  margin-top: 40px;
    214}
    1(function(){
    2    // Functions
    3    function buildQuiz(){
    4      // variable to store the HTML output
    5      const output = [];
    6  
    7      // for each question...
    8      myQuestions.forEach(
    9        (currentQuestion, questionNumber) => {
    10  
    11          // variable to store the list of answers
    12          const answers = [];
    13
    14          for(questionNumber in currentQuestion.answers){
    15
    16        
    17            answers.push(
    18              `<label>
    19                <input type="text" name="question${questionNumber}" placeholder="Company" size="20">
    20              </label>`
    21              
    22            );
    23          }
    24  
    25          // add this question to the output
    26          output.push(
    27            `<div class="slide">
    28              <div class="question"> ${currentQuestion.question} </div>
    29            </div>`
    30          );
    31        }
    32      );
    33  
    34      // finally combine our output list into one string of HTML and put it on the page
    35      quizContainer.innerHTML = output.join('');
    36    }
    37  
    38    function showResults(){
    39  
    40      // gather answer containers from our quiz
    41      const answerContainers = quizContainer.querySelectorAll('.answers');
    42  
    43      // keep track of user's answers
    44      let numCorrect = 0;
    45  
    46      // for each question...
    47      myQuestions.forEach( (currentQuestion, questionNumber) => {
    48  
    49        // find selected answer
    50        const answerContainer = answerContainers[questionNumber];
    51        const userAnswer = (answerContainer.querySelector('input').value);
    52        
    53        //if answer is blank
    54    if (userAnswer.length === 0 ) {
    55        alert("You must enter an answer to continue...");
    56        return false;
    57    }
    58
    59        // if answer is correct
    60        if(userAnswer.toLowerCase() === currentQuestion.correctAnswer.toLowerCase()){
    61          // add to the number of correct answers
    62          numCorrect++;
    63  
    64          // alert
    65         alert("CONGRATULATIONS! Your answer is correct! You have advanced to the next level.");
    66        }
    67        // if answer is wrong
    68        else{
    69          // alert
    70          alert("Wrong answer, please, keep trying...");
    71        }
    72      });
    73  
    74      // show number of correct answers out of total
    75      resultsContainer.innerHTML = `${numCorrect} out of ${myQuestions.length}`;
    76    }
    77  
    78    function showSlide(n) {
    79      slides[currentSlide].classList.remove('active-slide');
    80      slides[n].classList.add('active-slide');
    81      currentSlide = n;
    82      if(currentSlide === 0){
    83        previousButton.style.display = 'none';
    84      }
    85      else{
    86        previousButton.style.display = 'inline-block';
    87      }
    88      if(currentSlide === slides.length-1){
    89        nextButton.style.display = 'none';
    90        submitButton.style.display = 'inline-block';
    91      }
    92      else{
    93        nextButton.style.display = 'inline-block';
    94        submitButton.style.display = 'none';
    95      }
    96    }
    97  
    98    function showNextSlide() {
    99      showSlide(currentSlide + 1);
    100    }
    101  
    102    function showPreviousSlide() {
    103      showSlide(currentSlide - 1);
    104    }
    105  
    106    // Variables
    107    const quizContainer = document.getElementById('quiz');
    108    const resultsContainer = document.getElementById('results');
    109    const submitButton = document.getElementById('submit');
    110    
    111    const myQuestions = [
    112    {
    113      question: "Who invented JavaScript?",
    114      image: "https://i.postimg.cc/rmRj3SYt/nikecw.png",
    115      answers: "Write your answer here",
    116      correctAnswer: "Nike",
    117    },
    118    {
    119      question: "Which one of these is a JavaScript package manager?",
    120      image: "https://i.postimg.cc/rmRj3SYt/nikecw.png",
    121      correctAnswer: "Nike",
    122
    123    },
    124    {
    125      question: "Which tool can you use to ensure code quality?",
    126      image: "https://i.postimg.cc/rmRj3SYt/nikecw.png",
    127      correctAnswer: "Nike",
    128    }
    129];
    130    // Kick things off
    131    buildQuiz();
    132  
    133    // Pagination
    134    const previousButton = document.getElementById("previous");
    135    const nextButton = document.getElementById("next");
    136    const slides = document.querySelectorAll(".slide");
    137    let currentSlide = 0;
    138  
    139    // Show the first slide
    140    showSlide(currentSlide);
    141  
    142    // Event listeners
    143    submitButton.addEventListener('click', showResults);
    144    previousButton.addEventListener("click", showPreviousSlide);
    145    nextButton.addEventListener("click", showNextSlide);
    146  })();
    147  @import url(https://fonts.googleapis.com/css?family=Work+Sans:300,600);
    148
    149body{
    150    font-size: 20px;
    151    font-family: 'Work Sans', sans-serif;
    152    color: #333;
    153  font-weight: 300;
    154  text-align: center;
    155  background-color: #f8f6f0;
    156}
    157h1{
    158  font-weight: 300;
    159  margin: 0px;
    160  padding: 10px;
    161  font-size: 20px;
    162  background-color: #444;
    163  color: #fff;
    164}
    165.question{
    166  font-size: 30px;
    167  margin-bottom: 10px;
    168}
    169.answers {
    170  margin-bottom: 20px;
    171  text-align: left;
    172  display: inline-block;
    173}
    174.answers label{
    175  display: block;
    176  margin-bottom: 10px;
    177}
    178button{
    179  font-family: 'Work Sans', sans-serif;
    180    font-size: 22px;
    181    background-color: #279;
    182    color: #fff;
    183    border: 0px;
    184    border-radius: 3px;
    185    padding: 20px;
    186    cursor: pointer;
    187    margin-bottom: 20px;
    188}
    189button:hover{
    190    background-color: #38a;
    191}
    192
    193
    194
    195
    196
    197.slide{
    198  position: absolute;
    199  left: 0px;
    200  top: 0px;
    201  width: 100%;
    202  z-index: 1;
    203  opacity: 0;
    204  transition: opacity 0.5s;
    205}
    206.active-slide{
    207  opacity: 1;
    208  z-index: 2;
    209}
    210.quiz-container{
    211  position: relative;
    212  height: 200px;
    213  margin-top: 40px;
    214}    <!DOCTYPE html>
    215<html>
    216<head><title>trial</title>
    217  <link rel="stylesheet" href="trialcs.css">
    218<style>
    219            .color-cell {
    220                color: white;
    221            }
    222        </style>
    223  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    224<script src="logojs.js"></script>
    225</head>
    226<body>
    227
    228If I give you color wheel of 5 most dominant colors from 5 iconic logos, how many can you guess?
    229<div class="quiz-container">
    230  <div id="quiz"></div>
    231</div>
    232<button id="previous">Previous Question</button>
    233<button id="next">Next Question</button>
    234<button id="submit">Submit Quiz</button>
    235<div id="results"></div>
    236<script src="logocanvas.js"></script>
    237</body>
    238
    239</html>
    240
    241  

    ANSWER

    Answered 2022-Jan-21 at 17:00

    In your output.push I've added a input box, you need to pass your input box in this particular place. Input box I've added is just to show you the place you can add Input tag.

    1(function(){
    2    // Functions
    3    function buildQuiz(){
    4      // variable to store the HTML output
    5      const output = [];
    6  
    7      // for each question...
    8      myQuestions.forEach(
    9        (currentQuestion, questionNumber) => {
    10  
    11          // variable to store the list of answers
    12          const answers = [];
    13
    14          for(questionNumber in currentQuestion.answers){
    15
    16        
    17            answers.push(
    18              `<label>
    19                <input type="text" name="question${questionNumber}" placeholder="Company" size="20">
    20              </label>`
    21              
    22            );
    23          }
    24  
    25          // add this question to the output
    26          output.push(
    27            `<div class="slide">
    28              <div class="question"> ${currentQuestion.question} </div>
    29            </div>`
    30          );
    31        }
    32      );
    33  
    34      // finally combine our output list into one string of HTML and put it on the page
    35      quizContainer.innerHTML = output.join('');
    36    }
    37  
    38    function showResults(){
    39  
    40      // gather answer containers from our quiz
    41      const answerContainers = quizContainer.querySelectorAll('.answers');
    42  
    43      // keep track of user's answers
    44      let numCorrect = 0;
    45  
    46      // for each question...
    47      myQuestions.forEach( (currentQuestion, questionNumber) => {
    48  
    49        // find selected answer
    50        const answerContainer = answerContainers[questionNumber];
    51        const userAnswer = (answerContainer.querySelector('input').value);
    52        
    53        //if answer is blank
    54    if (userAnswer.length === 0 ) {
    55        alert("You must enter an answer to continue...");
    56        return false;
    57    }
    58
    59        // if answer is correct
    60        if(userAnswer.toLowerCase() === currentQuestion.correctAnswer.toLowerCase()){
    61          // add to the number of correct answers
    62          numCorrect++;
    63  
    64          // alert
    65         alert("CONGRATULATIONS! Your answer is correct! You have advanced to the next level.");
    66        }
    67        // if answer is wrong
    68        else{
    69          // alert
    70          alert("Wrong answer, please, keep trying...");
    71        }
    72      });
    73  
    74      // show number of correct answers out of total
    75      resultsContainer.innerHTML = `${numCorrect} out of ${myQuestions.length}`;
    76    }
    77  
    78    function showSlide(n) {
    79      slides[currentSlide].classList.remove('active-slide');
    80      slides[n].classList.add('active-slide');
    81      currentSlide = n;
    82      if(currentSlide === 0){
    83        previousButton.style.display = 'none';
    84      }
    85      else{
    86        previousButton.style.display = 'inline-block';
    87      }
    88      if(currentSlide === slides.length-1){
    89        nextButton.style.display = 'none';
    90        submitButton.style.display = 'inline-block';
    91      }
    92      else{
    93        nextButton.style.display = 'inline-block';
    94        submitButton.style.display = 'none';
    95      }
    96    }
    97  
    98    function showNextSlide() {
    99      showSlide(currentSlide + 1);
    100    }
    101  
    102    function showPreviousSlide() {
    103      showSlide(currentSlide - 1);
    104    }
    105  
    106    // Variables
    107    const quizContainer = document.getElementById('quiz');
    108    const resultsContainer = document.getElementById('results');
    109    const submitButton = document.getElementById('submit');
    110    
    111    const myQuestions = [
    112    {
    113      question: "Who invented JavaScript?",
    114      image: "https://i.postimg.cc/rmRj3SYt/nikecw.png",
    115      answers: "Write your answer here",
    116      correctAnswer: "Nike",
    117    },
    118    {
    119      question: "Which one of these is a JavaScript package manager?",
    120      image: "https://i.postimg.cc/rmRj3SYt/nikecw.png",
    121      correctAnswer: "Nike",
    122
    123    },
    124    {
    125      question: "Which tool can you use to ensure code quality?",
    126      image: "https://i.postimg.cc/rmRj3SYt/nikecw.png",
    127      correctAnswer: "Nike",
    128    }
    129];
    130    // Kick things off
    131    buildQuiz();
    132  
    133    // Pagination
    134    const previousButton = document.getElementById("previous");
    135    const nextButton = document.getElementById("next");
    136    const slides = document.querySelectorAll(".slide");
    137    let currentSlide = 0;
    138  
    139    // Show the first slide
    140    showSlide(currentSlide);
    141  
    142    // Event listeners
    143    submitButton.addEventListener('click', showResults);
    144    previousButton.addEventListener("click", showPreviousSlide);
    145    nextButton.addEventListener("click", showNextSlide);
    146  })();
    147  @import url(https://fonts.googleapis.com/css?family=Work+Sans:300,600);
    148
    149body{
    150    font-size: 20px;
    151    font-family: 'Work Sans', sans-serif;
    152    color: #333;
    153  font-weight: 300;
    154  text-align: center;
    155  background-color: #f8f6f0;
    156}
    157h1{
    158  font-weight: 300;
    159  margin: 0px;
    160  padding: 10px;
    161  font-size: 20px;
    162  background-color: #444;
    163  color: #fff;
    164}
    165.question{
    166  font-size: 30px;
    167  margin-bottom: 10px;
    168}
    169.answers {
    170  margin-bottom: 20px;
    171  text-align: left;
    172  display: inline-block;
    173}
    174.answers label{
    175  display: block;
    176  margin-bottom: 10px;
    177}
    178button{
    179  font-family: 'Work Sans', sans-serif;
    180    font-size: 22px;
    181    background-color: #279;
    182    color: #fff;
    183    border: 0px;
    184    border-radius: 3px;
    185    padding: 20px;
    186    cursor: pointer;
    187    margin-bottom: 20px;
    188}
    189button:hover{
    190    background-color: #38a;
    191}
    192
    193
    194
    195
    196
    197.slide{
    198  position: absolute;
    199  left: 0px;
    200  top: 0px;
    201  width: 100%;
    202  z-index: 1;
    203  opacity: 0;
    204  transition: opacity 0.5s;
    205}
    206.active-slide{
    207  opacity: 1;
    208  z-index: 2;
    209}
    210.quiz-container{
    211  position: relative;
    212  height: 200px;
    213  margin-top: 40px;
    214}    <!DOCTYPE html>
    215<html>
    216<head><title>trial</title>
    217  <link rel="stylesheet" href="trialcs.css">
    218<style>
    219            .color-cell {
    220                color: white;
    221            }
    222        </style>
    223  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    224<script src="logojs.js"></script>
    225</head>
    226<body>
    227
    228If I give you color wheel of 5 most dominant colors from 5 iconic logos, how many can you guess?
    229<div class="quiz-container">
    230  <div id="quiz"></div>
    231</div>
    232<button id="previous">Previous Question</button>
    233<button id="next">Next Question</button>
    234<button id="submit">Submit Quiz</button>
    235<div id="results"></div>
    236<script src="logocanvas.js"></script>
    237</body>
    238
    239</html>
    240
    241  (function () {
    242    // Functions
    243    function buildQuiz() {
    244        // variable to store the HTML output
    245        const output = [];
    246
    247        // for each question...
    248        myQuestions.forEach((currentQuestion, questionNumber) => {
    249            // variable to store the list of answers
    250            const answers = [];
    251
    252            for (questionNumber in currentQuestion.answers) {
    253                answers.push(
    254                    `<label>
    255                <input type="text" name="question${questionNumber}" placeholder="Company" size="20">
    256              </label>`
    257                );
    258            }
    259
    260            // add this question to the output
    261            output.push(
    262                `<div class="slide">
    263              <div class="question"> ${currentQuestion.question} </div>
    264
    265                            
    266                <input type="text" name="question${questionNumber}" placeholder="Write answer here" size="20">
    267            </div>`
    268            );
    269        });
    270
    271        // finally combine our output list into one string of HTML and put it on the page
    272        quizContainer.innerHTML = output.join("");
    273    }
    274
    275    function showResults() {
    276        // gather answer containers from our quiz
    277        const answerContainers = quizContainer.querySelectorAll(".answers");
    278
    279        // keep track of user's answers
    280        let numCorrect = 0;
    281
    282        // for each question...
    283        myQuestions.forEach((currentQuestion, questionNumber) => {
    284            // find selected answer
    285            const answerContainer = answerContainers[questionNumber];
    286            const userAnswer = answerContainer.querySelector("input").value;
    287
    288            //if answer is blank
    289            if (userAnswer.length === 0) {
    290                alert("You must enter an answer to continue...");
    291                return false;
    292            }
    293
    294            // if answer is correct
    295            if (
    296                userAnswer.toLowerCase() === currentQuestion.correctAnswer.toLowerCase()
    297            ) {
    298                // add to the number of correct answers
    299                numCorrect++;
    300
    301                // alert
    302                alert(
    303                    "CONGRATULATIONS! Your answer is correct! You have advanced to the next level."
    304                );
    305            }
    306            // if answer is wrong
    307            else {
    308                // alert
    309                alert("Wrong answer, please, keep trying...");
    310            }
    311        });
    312
    313        // show number of correct answers out of total
    314        resultsContainer.innerHTML = `${numCorrect} out of ${myQuestions.length}`;
    315    }
    316
    317    function showSlide(n) {
    318        slides[currentSlide].classList.remove("active-slide");
    319        slides[n].classList.add("active-slide");
    320        currentSlide = n;
    321        if (currentSlide === 0) {
    322            previousButton.style.display = "none";
    323        } else {
    324            previousButton.style.display = "inline-block";
    325        }
    326        if (currentSlide === slides.length - 1) {
    327            nextButton.style.display = "none";
    328            submitButton.style.display = "inline-block";
    329        } else {
    330            nextButton.style.display = "inline-block";
    331            submitButton.style.display = "none";
    332        }
    333    }
    334
    335    function showNextSlide() {
    336        showSlide(currentSlide + 1);
    337    }
    338
    339    function showPreviousSlide() {
    340        showSlide(currentSlide - 1);
    341    }
    342
    343    // Variables
    344    const quizContainer = document.getElementById("quiz");
    345    const resultsContainer = document.getElementById("results");
    346    const submitButton = document.getElementById("submit");
    347
    348    const myQuestions = [
    349        {
    350            question: "Who invented JavaScript?",
    351            image: "https://i.postimg.cc/rmRj3SYt/nikecw.png",
    352            answers: "Write your answer here",
    353            correctAnswer: "Nike"
    354        },
    355        {
    356            question: "Which one of these is a JavaScript package manager?",
    357            image: "https://i.postimg.cc/rmRj3SYt/nikecw.png",
    358            answers: "Write your answer here",
    359            correctAnswer: "Nike"
    360        },
    361        {
    362            question: "Which tool can you use to ensure code quality?",
    363            image: "https://i.postimg.cc/rmRj3SYt/nikecw.png",
    364            answers: "Write your answer here",
    365            correctAnswer: "Nike"
    366        }
    367    ];
    368    // Kick things off
    369    buildQuiz();
    370
    371    // Pagination
    372    const previousButton = document.getElementById("previous");
    373    const nextButton = document.getElementById("next");
    374    const slides = document.querySelectorAll(".slide");
    375    let currentSlide = 0;
    376
    377    // Show the first slide
    378    showSlide(currentSlide);
    379
    380    // Event listeners
    381    submitButton.addEventListener("click", showResults);
    382    previousButton.addEventListener("click", showPreviousSlide);
    383    nextButton.addEventListener("click", showNextSlide);
    384})();
    1(function(){
    2    // Functions
    3    function buildQuiz(){
    4      // variable to store the HTML output
    5      const output = [];
    6  
    7      // for each question...
    8      myQuestions.forEach(
    9        (currentQuestion, questionNumber) => {
    10  
    11          // variable to store the list of answers
    12          const answers = [];
    13
    14          for(questionNumber in currentQuestion.answers){
    15
    16        
    17            answers.push(
    18              `<label>
    19                <input type="text" name="question${questionNumber}" placeholder="Company" size="20">
    20              </label>`
    21              
    22            );
    23          }
    24  
    25          // add this question to the output
    26          output.push(
    27            `<div class="slide">
    28              <div class="question"> ${currentQuestion.question} </div>
    29            </div>`
    30          );
    31        }
    32      );
    33  
    34      // finally combine our output list into one string of HTML and put it on the page
    35      quizContainer.innerHTML = output.join('');
    36    }
    37  
    38    function showResults(){
    39  
    40      // gather answer containers from our quiz
    41      const answerContainers = quizContainer.querySelectorAll('.answers');
    42  
    43      // keep track of user's answers
    44      let numCorrect = 0;
    45  
    46      // for each question...
    47      myQuestions.forEach( (currentQuestion, questionNumber) => {
    48  
    49        // find selected answer
    50        const answerContainer = answerContainers[questionNumber];
    51        const userAnswer = (answerContainer.querySelector('input').value);
    52        
    53        //if answer is blank
    54    if (userAnswer.length === 0 ) {
    55        alert("You must enter an answer to continue...");
    56        return false;
    57    }
    58
    59        // if answer is correct
    60        if(userAnswer.toLowerCase() === currentQuestion.correctAnswer.toLowerCase()){
    61          // add to the number of correct answers
    62          numCorrect++;
    63  
    64          // alert
    65         alert("CONGRATULATIONS! Your answer is correct! You have advanced to the next level.");
    66        }
    67        // if answer is wrong
    68        else{
    69          // alert
    70          alert("Wrong answer, please, keep trying...");
    71        }
    72      });
    73  
    74      // show number of correct answers out of total
    75      resultsContainer.innerHTML = `${numCorrect} out of ${myQuestions.length}`;
    76    }
    77  
    78    function showSlide(n) {
    79      slides[currentSlide].classList.remove('active-slide');
    80      slides[n].classList.add('active-slide');
    81      currentSlide = n;
    82      if(currentSlide === 0){
    83        previousButton.style.display = 'none';
    84      }
    85      else{
    86        previousButton.style.display = 'inline-block';
    87      }
    88      if(currentSlide === slides.length-1){
    89        nextButton.style.display = 'none';
    90        submitButton.style.display = 'inline-block';
    91      }
    92      else{
    93        nextButton.style.display = 'inline-block';
    94        submitButton.style.display = 'none';
    95      }
    96    }
    97  
    98    function showNextSlide() {
    99      showSlide(currentSlide + 1);
    100    }
    101  
    102    function showPreviousSlide() {
    103      showSlide(currentSlide - 1);
    104    }
    105  
    106    // Variables
    107    const quizContainer = document.getElementById('quiz');
    108    const resultsContainer = document.getElementById('results');
    109    const submitButton = document.getElementById('submit');
    110    
    111    const myQuestions = [
    112    {
    113      question: "Who invented JavaScript?",
    114      image: "https://i.postimg.cc/rmRj3SYt/nikecw.png",
    115      answers: "Write your answer here",
    116      correctAnswer: "Nike",
    117    },
    118    {
    119      question: "Which one of these is a JavaScript package manager?",
    120      image: "https://i.postimg.cc/rmRj3SYt/nikecw.png",
    121      correctAnswer: "Nike",
    122
    123    },
    124    {
    125      question: "Which tool can you use to ensure code quality?",
    126      image: "https://i.postimg.cc/rmRj3SYt/nikecw.png",
    127      correctAnswer: "Nike",
    128    }
    129];
    130    // Kick things off
    131    buildQuiz();
    132  
    133    // Pagination
    134    const previousButton = document.getElementById("previous");
    135    const nextButton = document.getElementById("next");
    136    const slides = document.querySelectorAll(".slide");
    137    let currentSlide = 0;
    138  
    139    // Show the first slide
    140    showSlide(currentSlide);
    141  
    142    // Event listeners
    143    submitButton.addEventListener('click', showResults);
    144    previousButton.addEventListener("click", showPreviousSlide);
    145    nextButton.addEventListener("click", showNextSlide);
    146  })();
    147  @import url(https://fonts.googleapis.com/css?family=Work+Sans:300,600);
    148
    149body{
    150    font-size: 20px;
    151    font-family: 'Work Sans', sans-serif;
    152    color: #333;
    153  font-weight: 300;
    154  text-align: center;
    155  background-color: #f8f6f0;
    156}
    157h1{
    158  font-weight: 300;
    159  margin: 0px;
    160  padding: 10px;
    161  font-size: 20px;
    162  background-color: #444;
    163  color: #fff;
    164}
    165.question{
    166  font-size: 30px;
    167  margin-bottom: 10px;
    168}
    169.answers {
    170  margin-bottom: 20px;
    171  text-align: left;
    172  display: inline-block;
    173}
    174.answers label{
    175  display: block;
    176  margin-bottom: 10px;
    177}
    178button{
    179  font-family: 'Work Sans', sans-serif;
    180    font-size: 22px;
    181    background-color: #279;
    182    color: #fff;
    183    border: 0px;
    184    border-radius: 3px;
    185    padding: 20px;
    186    cursor: pointer;
    187    margin-bottom: 20px;
    188}
    189button:hover{
    190    background-color: #38a;
    191}
    192
    193
    194
    195
    196
    197.slide{
    198  position: absolute;
    199  left: 0px;
    200  top: 0px;
    201  width: 100%;
    202  z-index: 1;
    203  opacity: 0;
    204  transition: opacity 0.5s;
    205}
    206.active-slide{
    207  opacity: 1;
    208  z-index: 2;
    209}
    210.quiz-container{
    211  position: relative;
    212  height: 200px;
    213  margin-top: 40px;
    214}    <!DOCTYPE html>
    215<html>
    216<head><title>trial</title>
    217  <link rel="stylesheet" href="trialcs.css">
    218<style>
    219            .color-cell {
    220                color: white;
    221            }
    222        </style>
    223  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    224<script src="logojs.js"></script>
    225</head>
    226<body>
    227
    228If I give you color wheel of 5 most dominant colors from 5 iconic logos, how many can you guess?
    229<div class="quiz-container">
    230  <div id="quiz"></div>
    231</div>
    232<button id="previous">Previous Question</button>
    233<button id="next">Next Question</button>
    234<button id="submit">Submit Quiz</button>
    235<div id="results"></div>
    236<script src="logocanvas.js"></script>
    237</body>
    238
    239</html>
    240
    241  (function () {
    242    // Functions
    243    function buildQuiz() {
    244        // variable to store the HTML output
    245        const output = [];
    246
    247        // for each question...
    248        myQuestions.forEach((currentQuestion, questionNumber) => {
    249            // variable to store the list of answers
    250            const answers = [];
    251
    252            for (questionNumber in currentQuestion.answers) {
    253                answers.push(
    254                    `<label>
    255                <input type="text" name="question${questionNumber}" placeholder="Company" size="20">
    256              </label>`
    257                );
    258            }
    259
    260            // add this question to the output
    261            output.push(
    262                `<div class="slide">
    263              <div class="question"> ${currentQuestion.question} </div>
    264
    265                            
    266                <input type="text" name="question${questionNumber}" placeholder="Write answer here" size="20">
    267            </div>`
    268            );
    269        });
    270
    271        // finally combine our output list into one string of HTML and put it on the page
    272        quizContainer.innerHTML = output.join("");
    273    }
    274
    275    function showResults() {
    276        // gather answer containers from our quiz
    277        const answerContainers = quizContainer.querySelectorAll(".answers");
    278
    279        // keep track of user's answers
    280        let numCorrect = 0;
    281
    282        // for each question...
    283        myQuestions.forEach((currentQuestion, questionNumber) => {
    284            // find selected answer
    285            const answerContainer = answerContainers[questionNumber];
    286            const userAnswer = answerContainer.querySelector("input").value;
    287
    288            //if answer is blank
    289            if (userAnswer.length === 0) {
    290                alert("You must enter an answer to continue...");
    291                return false;
    292            }
    293
    294            // if answer is correct
    295            if (
    296                userAnswer.toLowerCase() === currentQuestion.correctAnswer.toLowerCase()
    297            ) {
    298                // add to the number of correct answers
    299                numCorrect++;
    300
    301                // alert
    302                alert(
    303                    "CONGRATULATIONS! Your answer is correct! You have advanced to the next level."
    304                );
    305            }
    306            // if answer is wrong
    307            else {
    308                // alert
    309                alert("Wrong answer, please, keep trying...");
    310            }
    311        });
    312
    313        // show number of correct answers out of total
    314        resultsContainer.innerHTML = `${numCorrect} out of ${myQuestions.length}`;
    315    }
    316
    317    function showSlide(n) {
    318        slides[currentSlide].classList.remove("active-slide");
    319        slides[n].classList.add("active-slide");
    320        currentSlide = n;
    321        if (currentSlide === 0) {
    322            previousButton.style.display = "none";
    323        } else {
    324            previousButton.style.display = "inline-block";
    325        }
    326        if (currentSlide === slides.length - 1) {
    327            nextButton.style.display = "none";
    328            submitButton.style.display = "inline-block";
    329        } else {
    330            nextButton.style.display = "inline-block";
    331            submitButton.style.display = "none";
    332        }
    333    }
    334
    335    function showNextSlide() {
    336        showSlide(currentSlide + 1);
    337    }
    338
    339    function showPreviousSlide() {
    340        showSlide(currentSlide - 1);
    341    }
    342
    343    // Variables
    344    const quizContainer = document.getElementById("quiz");
    345    const resultsContainer = document.getElementById("results");
    346    const submitButton = document.getElementById("submit");
    347
    348    const myQuestions = [
    349        {
    350            question: "Who invented JavaScript?",
    351            image: "https://i.postimg.cc/rmRj3SYt/nikecw.png",
    352            answers: "Write your answer here",
    353            correctAnswer: "Nike"
    354        },
    355        {
    356            question: "Which one of these is a JavaScript package manager?",
    357            image: "https://i.postimg.cc/rmRj3SYt/nikecw.png",
    358            answers: "Write your answer here",
    359            correctAnswer: "Nike"
    360        },
    361        {
    362            question: "Which tool can you use to ensure code quality?",
    363            image: "https://i.postimg.cc/rmRj3SYt/nikecw.png",
    364            answers: "Write your answer here",
    365            correctAnswer: "Nike"
    366        }
    367    ];
    368    // Kick things off
    369    buildQuiz();
    370
    371    // Pagination
    372    const previousButton = document.getElementById("previous");
    373    const nextButton = document.getElementById("next");
    374    const slides = document.querySelectorAll(".slide");
    375    let currentSlide = 0;
    376
    377    // Show the first slide
    378    showSlide(currentSlide);
    379
    380    // Event listeners
    381    submitButton.addEventListener("click", showResults);
    382    previousButton.addEventListener("click", showPreviousSlide);
    383    nextButton.addEventListener("click", showNextSlide);
    384})();@import url(https://fonts.googleapis.com/css?family=Work+Sans:300,600);
    385
    386body {
    387    font-size: 20px;
    388    font-family: "Work Sans", sans-serif;
    389    color: #333;
    390    font-weight: 300;
    391    text-align: center;
    392    background-color: #f8f6f0;
    393}
    394h1 {
    395    font-weight: 300;
    396    margin: 0px;
    397    padding: 10px;
    398    font-size: 20px;
    399    background-color: #444;
    400    color: #fff;
    401}
    402.question {
    403    font-size: 30px;
    404    margin-bottom: 10px;
    405}
    406.answers {
    407    margin-bottom: 20px;
    408    text-align: left;
    409    display: inline-block;
    410}
    411.answers label {
    412    display: block;
    413    margin-bottom: 10px;
    414}
    415button {
    416    font-family: "Work Sans", sans-serif;
    417    font-size: 22px;
    418    background-color: #279;
    419    color: #fff;
    420    border: 0px;
    421    border-radius: 3px;
    422    padding: 20px;
    423    cursor: pointer;
    424    margin-bottom: 20px;
    425}
    426button:hover {
    427    background-color: #38a;
    428}
    429
    430.slide {
    431    position: absolute;
    432    left: 0px;
    433    top: 0px;
    434    width: 100%;
    435    z-index: 1;
    436    opacity: 0;
    437    transition: opacity 0.5s;
    438}
    439.active-slide {
    440    opacity: 1;
    441    z-index: 2;
    442}
    443.quiz-container {
    444    position: relative;
    445    height: 200px;
    446    margin-top: 40px;
    447}
    1(function(){
    2    // Functions
    3    function buildQuiz(){
    4      // variable to store the HTML output
    5      const output = [];
    6  
    7      // for each question...
    8      myQuestions.forEach(
    9        (currentQuestion, questionNumber) => {
    10  
    11          // variable to store the list of answers
    12          const answers = [];
    13
    14          for(questionNumber in currentQuestion.answers){
    15
    16        
    17            answers.push(
    18              `<label>
    19                <input type="text" name="question${questionNumber}" placeholder="Company" size="20">
    20              </label>`
    21              
    22            );
    23          }
    24  
    25          // add this question to the output
    26          output.push(
    27            `<div class="slide">
    28              <div class="question"> ${currentQuestion.question} </div>
    29            </div>`
    30          );
    31        }
    32      );
    33  
    34      // finally combine our output list into one string of HTML and put it on the page
    35      quizContainer.innerHTML = output.join('');
    36    }
    37  
    38    function showResults(){
    39  
    40      // gather answer containers from our quiz
    41      const answerContainers = quizContainer.querySelectorAll('.answers');
    42  
    43      // keep track of user's answers
    44      let numCorrect = 0;
    45  
    46      // for each question...
    47      myQuestions.forEach( (currentQuestion, questionNumber) => {
    48  
    49        // find selected answer
    50        const answerContainer = answerContainers[questionNumber];
    51        const userAnswer = (answerContainer.querySelector('input').value);
    52        
    53        //if answer is blank
    54    if (userAnswer.length === 0 ) {
    55        alert("You must enter an answer to continue...");
    56        return false;
    57    }
    58
    59        // if answer is correct
    60        if(userAnswer.toLowerCase() === currentQuestion.correctAnswer.toLowerCase()){
    61          // add to the number of correct answers
    62          numCorrect++;
    63  
    64          // alert
    65         alert("CONGRATULATIONS! Your answer is correct! You have advanced to the next level.");
    66        }
    67        // if answer is wrong
    68        else{
    69          // alert
    70          alert("Wrong answer, please, keep trying...");
    71        }
    72      });
    73  
    74      // show number of correct answers out of total
    75      resultsContainer.innerHTML = `${numCorrect} out of ${myQuestions.length}`;
    76    }
    77  
    78    function showSlide(n) {
    79      slides[currentSlide].classList.remove('active-slide');
    80      slides[n].classList.add('active-slide');
    81      currentSlide = n;
    82      if(currentSlide === 0){
    83        previousButton.style.display = 'none';
    84      }
    85      else{
    86        previousButton.style.display = 'inline-block';
    87      }
    88      if(currentSlide === slides.length-1){
    89        nextButton.style.display = 'none';
    90        submitButton.style.display = 'inline-block';
    91      }
    92      else{
    93        nextButton.style.display = 'inline-block';
    94        submitButton.style.display = 'none';
    95      }
    96    }
    97  
    98    function showNextSlide() {
    99      showSlide(currentSlide + 1);
    100    }
    101  
    102    function showPreviousSlide() {
    103      showSlide(currentSlide - 1);
    104    }
    105  
    106    // Variables
    107    const quizContainer = document.getElementById('quiz');
    108    const resultsContainer = document.getElementById('results');
    109    const submitButton = document.getElementById('submit');
    110    
    111    const myQuestions = [
    112    {
    113      question: "Who invented JavaScript?",
    114      image: "https://i.postimg.cc/rmRj3SYt/nikecw.png",
    115      answers: "Write your answer here",
    116      correctAnswer: "Nike",
    117    },
    118    {
    119      question: "Which one of these is a JavaScript package manager?",
    120      image: "https://i.postimg.cc/rmRj3SYt/nikecw.png",
    121      correctAnswer: "Nike",
    122
    123    },
    124    {
    125      question: "Which tool can you use to ensure code quality?",
    126      image: "https://i.postimg.cc/rmRj3SYt/nikecw.png",
    127      correctAnswer: "Nike",
    128    }
    129];
    130    // Kick things off
    131    buildQuiz();
    132  
    133    // Pagination
    134    const previousButton = document.getElementById("previous");
    135    const nextButton = document.getElementById("next");
    136    const slides = document.querySelectorAll(".slide");
    137    let currentSlide = 0;
    138  
    139    // Show the first slide
    140    showSlide(currentSlide);
    141  
    142    // Event listeners
    143    submitButton.addEventListener('click', showResults);
    144    previousButton.addEventListener("click", showPreviousSlide);
    145    nextButton.addEventListener("click", showNextSlide);
    146  })();
    147  @import url(https://fonts.googleapis.com/css?family=Work+Sans:300,600);
    148
    149body{
    150    font-size: 20px;
    151    font-family: 'Work Sans', sans-serif;
    152    color: #333;
    153  font-weight: 300;
    154  text-align: center;
    155  background-color: #f8f6f0;
    156}
    157h1{
    158  font-weight: 300;
    159  margin: 0px;
    160  padding: 10px;
    161  font-size: 20px;
    162  background-color: #444;
    163  color: #fff;
    164}
    165.question{
    166  font-size: 30px;
    167  margin-bottom: 10px;
    168}
    169.answers {
    170  margin-bottom: 20px;
    171  text-align: left;
    172  display: inline-block;
    173}
    174.answers label{
    175  display: block;
    176  margin-bottom: 10px;
    177}
    178button{
    179  font-family: 'Work Sans', sans-serif;
    180    font-size: 22px;
    181    background-color: #279;
    182    color: #fff;
    183    border: 0px;
    184    border-radius: 3px;
    185    padding: 20px;
    186    cursor: pointer;
    187    margin-bottom: 20px;
    188}
    189button:hover{
    190    background-color: #38a;
    191}
    192
    193
    194
    195
    196
    197.slide{
    198  position: absolute;
    199  left: 0px;
    200  top: 0px;
    201  width: 100%;
    202  z-index: 1;
    203  opacity: 0;
    204  transition: opacity 0.5s;
    205}
    206.active-slide{
    207  opacity: 1;
    208  z-index: 2;
    209}
    210.quiz-container{
    211  position: relative;
    212  height: 200px;
    213  margin-top: 40px;
    214}    <!DOCTYPE html>
    215<html>
    216<head><title>trial</title>
    217  <link rel="stylesheet" href="trialcs.css">
    218<style>
    219            .color-cell {
    220                color: white;
    221            }
    222        </style>
    223  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    224<script src="logojs.js"></script>
    225</head>
    226<body>
    227
    228If I give you color wheel of 5 most dominant colors from 5 iconic logos, how many can you guess?
    229<div class="quiz-container">
    230  <div id="quiz"></div>
    231</div>
    232<button id="previous">Previous Question</button>
    233<button id="next">Next Question</button>
    234<button id="submit">Submit Quiz</button>
    235<div id="results"></div>
    236<script src="logocanvas.js"></script>
    237</body>
    238
    239</html>
    240
    241  (function () {
    242    // Functions
    243    function buildQuiz() {
    244        // variable to store the HTML output
    245        const output = [];
    246
    247        // for each question...
    248        myQuestions.forEach((currentQuestion, questionNumber) => {
    249            // variable to store the list of answers
    250            const answers = [];
    251
    252            for (questionNumber in currentQuestion.answers) {
    253                answers.push(
    254                    `<label>
    255                <input type="text" name="question${questionNumber}" placeholder="Company" size="20">
    256              </label>`
    257                );
    258            }
    259
    260            // add this question to the output
    261            output.push(
    262                `<div class="slide">
    263              <div class="question"> ${currentQuestion.question} </div>
    264
    265                            
    266                <input type="text" name="question${questionNumber}" placeholder="Write answer here" size="20">
    267            </div>`
    268            );
    269        });
    270
    271        // finally combine our output list into one string of HTML and put it on the page
    272        quizContainer.innerHTML = output.join("");
    273    }
    274
    275    function showResults() {
    276        // gather answer containers from our quiz
    277        const answerContainers = quizContainer.querySelectorAll(".answers");
    278
    279        // keep track of user's answers
    280        let numCorrect = 0;
    281
    282        // for each question...
    283        myQuestions.forEach((currentQuestion, questionNumber) => {
    284            // find selected answer
    285            const answerContainer = answerContainers[questionNumber];
    286            const userAnswer = answerContainer.querySelector("input").value;
    287
    288            //if answer is blank
    289            if (userAnswer.length === 0) {
    290                alert("You must enter an answer to continue...");
    291                return false;
    292            }
    293
    294            // if answer is correct
    295            if (
    296                userAnswer.toLowerCase() === currentQuestion.correctAnswer.toLowerCase()
    297            ) {
    298                // add to the number of correct answers
    299                numCorrect++;
    300
    301                // alert
    302                alert(
    303                    "CONGRATULATIONS! Your answer is correct! You have advanced to the next level."
    304                );
    305            }
    306            // if answer is wrong
    307            else {
    308                // alert
    309                alert("Wrong answer, please, keep trying...");
    310            }
    311        });
    312
    313        // show number of correct answers out of total
    314        resultsContainer.innerHTML = `${numCorrect} out of ${myQuestions.length}`;
    315    }
    316
    317    function showSlide(n) {
    318        slides[currentSlide].classList.remove("active-slide");
    319        slides[n].classList.add("active-slide");
    320        currentSlide = n;
    321        if (currentSlide === 0) {
    322            previousButton.style.display = "none";
    323        } else {
    324            previousButton.style.display = "inline-block";
    325        }
    326        if (currentSlide === slides.length - 1) {
    327            nextButton.style.display = "none";
    328            submitButton.style.display = "inline-block";
    329        } else {
    330            nextButton.style.display = "inline-block";
    331            submitButton.style.display = "none";
    332        }
    333    }
    334
    335    function showNextSlide() {
    336        showSlide(currentSlide + 1);
    337    }
    338
    339    function showPreviousSlide() {
    340        showSlide(currentSlide - 1);
    341    }
    342
    343    // Variables
    344    const quizContainer = document.getElementById("quiz");
    345    const resultsContainer = document.getElementById("results");
    346    const submitButton = document.getElementById("submit");
    347
    348    const myQuestions = [
    349        {
    350            question: "Who invented JavaScript?",
    351            image: "https://i.postimg.cc/rmRj3SYt/nikecw.png",
    352            answers: "Write your answer here",
    353            correctAnswer: "Nike"
    354        },
    355        {
    356            question: "Which one of these is a JavaScript package manager?",
    357            image: "https://i.postimg.cc/rmRj3SYt/nikecw.png",
    358            answers: "Write your answer here",
    359            correctAnswer: "Nike"
    360        },
    361        {
    362            question: "Which tool can you use to ensure code quality?",
    363            image: "https://i.postimg.cc/rmRj3SYt/nikecw.png",
    364            answers: "Write your answer here",
    365            correctAnswer: "Nike"
    366        }
    367    ];
    368    // Kick things off
    369    buildQuiz();
    370
    371    // Pagination
    372    const previousButton = document.getElementById("previous");
    373    const nextButton = document.getElementById("next");
    374    const slides = document.querySelectorAll(".slide");
    375    let currentSlide = 0;
    376
    377    // Show the first slide
    378    showSlide(currentSlide);
    379
    380    // Event listeners
    381    submitButton.addEventListener("click", showResults);
    382    previousButton.addEventListener("click", showPreviousSlide);
    383    nextButton.addEventListener("click", showNextSlide);
    384})();@import url(https://fonts.googleapis.com/css?family=Work+Sans:300,600);
    385
    386body {
    387    font-size: 20px;
    388    font-family: "Work Sans", sans-serif;
    389    color: #333;
    390    font-weight: 300;
    391    text-align: center;
    392    background-color: #f8f6f0;
    393}
    394h1 {
    395    font-weight: 300;
    396    margin: 0px;
    397    padding: 10px;
    398    font-size: 20px;
    399    background-color: #444;
    400    color: #fff;
    401}
    402.question {
    403    font-size: 30px;
    404    margin-bottom: 10px;
    405}
    406.answers {
    407    margin-bottom: 20px;
    408    text-align: left;
    409    display: inline-block;
    410}
    411.answers label {
    412    display: block;
    413    margin-bottom: 10px;
    414}
    415button {
    416    font-family: "Work Sans", sans-serif;
    417    font-size: 22px;
    418    background-color: #279;
    419    color: #fff;
    420    border: 0px;
    421    border-radius: 3px;
    422    padding: 20px;
    423    cursor: pointer;
    424    margin-bottom: 20px;
    425}
    426button:hover {
    427    background-color: #38a;
    428}
    429
    430.slide {
    431    position: absolute;
    432    left: 0px;
    433    top: 0px;
    434    width: 100%;
    435    z-index: 1;
    436    opacity: 0;
    437    transition: opacity 0.5s;
    438}
    439.active-slide {
    440    opacity: 1;
    441    z-index: 2;
    442}
    443.quiz-container {
    444    position: relative;
    445    height: 200px;
    446    margin-top: 40px;
    447}If I give you color wheel of 5 most dominant colors from 5 iconic logos, how many can you guess?
    448<div class="quiz-container">
    449    <div id="quiz"></div>
    450</div>
    451<button id="previous">Previous Question</button>
    452<button id="next">Next Question</button>
    453<button id="submit">Submit Quiz</button>
    454<div id="results"></div>

    Source https://stackoverflow.com/questions/70804423

    QUESTION

    Exposed ORM: DSL vs DAO in Many-to many relationships best practices

    Asked 2022-Jan-17 at 01:50

    I am setting up some many-to-many relationships and have so far been using the Exposed DSL pattern (as opposed to DAO). However, creating many-to-many relationships seem to only be possible using the DAO approach.

    I know it is probably fine to use the two patterns interchangeably, but as I set up my project and move forward, I'm wondering what the best approach is from the perspective of code quality. Use them both or switch to DAO? Or the third option is that this question represents a misguided understanding of Kotlin and/or Exposed (new to both), in which case, where am I going wrong? Thanks in advance

    ANSWER

    Answered 2022-Jan-17 at 01:50

    It is possible to use DSL to create many-to-many relationships for tables. However whether or not you should use DSL or DAO or both together would really be up to you and whether or not it makes the code easier or harder to read and maintain.

    Here is a basic example of a many to many relationship with DSL.

    1import org.jetbrains.exposed.dao.id.IntIdTable
    2import org.jetbrains.exposed.sql.*
    3import org.jetbrains.exposed.sql.transactions.transaction
    4
    5object Users : IntIdTable() {
    6    val username = varchar("username", 50)
    7}
    8
    9object Permissions : IntIdTable() {
    10    val name = varchar("name", 50)
    11}
    12
    13object UserPermissionsJunctionTable : IntIdTable() {
    14    val user = reference("user", Users)
    15    val permission = reference("permission", Permissions)
    16}
    17
    18fun main(args: Array<String>) {
    19    val db = Database.connect("jdbc:sqlite:test.db", "org.sqlite.JDBC")
    20
    21    transaction {
    22        addLogger(StdOutSqlLogger)
    23
    24        SchemaUtils.create(Users, Permissions, UserPermissionsJunctionTable)
    25
    26        val userId = Users.insertAndGetId {
    27            it[username] = "john.smith"
    28        }
    29
    30        val readPermissionId = Permissions.insertAndGetId {
    31            it[name] = "read"
    32        }
    33
    34        val writePermissionId = Permissions.insertAndGetId {
    35            it[name] = "write"
    36        }
    37
    38        UserPermissionsJunctionTable.insert {
    39            it[user] = userId
    40            it[permission] = readPermissionId
    41        }
    42
    43        UserPermissionsJunctionTable.insert {
    44            it[user] = userId
    45            it[permission] = writePermissionId
    46        }
    47
    48        val result = Users
    49            .join(UserPermissionsJunctionTable, JoinType.INNER, additionalConstraint = {
    50                Users.id eq UserPermissionsJunctionTable.user
    51        })
    52            .join(Permissions, JoinType.INNER, additionalConstraint = {
    53                UserPermissionsJunctionTable.permission eq Permissions.id
    54        })
    55            .slice(Users.username, Permissions.name).selectAll().map {
    56                it[Users.username] to it[Permissions.name]
    57        }
    58
    59        println(result)
    60    }
    61}
    62

    This prints [(john.smith, read), (john.smith, write)]

    Source https://stackoverflow.com/questions/70734941

    QUESTION

    How do I output only a capture group with sed

    Asked 2022-Jan-14 at 15:48

    I have an input file

    1
    2Werkzeug==2.0.2 # https://github.com/pallets/werkzeug
    3ipdb==0.13.9  # https://github.com/gotcha/ipdb
    4psycopg2==2.9.1  # https://github.com/psycopg/psycopg2
    5watchgod==0.7  # https://github.com/samuelcolvin/watchgod
    6
    7# Testing
    8# ------------------------------------------------------------------------------
    9mypy==0.910  # https://github.com/python/mypy
    10django-stubs==1.8.0  # https://github.com/typeddjango/django-stubs
    11pytest==6.2.5  # https://github.com/pytest-dev/pytest
    12pytest-sugar==0.9.4  # https://github.com/Frozenball/pytest-sugar
    13djangorestframework-stubs==1.4.0  # https://github.com/typeddjango/djangorestframework-stubs
    14
    15# Documentation
    16# ------------------------------------------------------------------------------
    17sphinx==4.2.0  # https://github.com/sphinx-doc/sphinx
    18sphinx-autobuild==2021.3.14 # https://github.com/GaretJax/sphinx-autobuild
    19
    20# Code quality
    21# ------------------------------------------------------------------------------
    22flake8==3.9.2  # https://github.com/PyCQA/flake8
    23flake8-isort==4.0.0  # https://github.com/gforcada/flake8-isort
    24coverage==6.0.2  # https://github.com/nedbat/coveragepy
    25black==21.9b0  # https://github.com/psf/black
    26pylint-django==2.4.4  # https://github.com/PyCQA/pylint-django
    27pylint-celery==0.3  # https://github.com/PyCQA/pylint-celery
    28pre-commit==2.15.0  # https://github.com/pre-commit/pre-commit
    29
    30# Django
    31# ------------------------------------------------------------------------------
    32factory-boy==3.2.0  # https://github.com/FactoryBoy/factory_boy
    33
    34django-debug-toolbar==3.2.2  # https://github.com/jazzband/django-debug-toolbar
    35django-extensions==3.1.3  # https://github.com/django-extensions/django-extensions
    36django-coverage-plugin==2.0.1  # https://github.com/nedbat/django_coverage_plugin
    37pytest-django==4.4.0  # https://github.com/pytest-dev/pytest-django
    38

    and I am trying to extract the parts before the # for every line beginning with pytest using this command

    sed -nE "s/(^pytest.+)#/\1/p" ./requirements/local.txt

    Expected output

    1
    2Werkzeug==2.0.2 # https://github.com/pallets/werkzeug
    3ipdb==0.13.9  # https://github.com/gotcha/ipdb
    4psycopg2==2.9.1  # https://github.com/psycopg/psycopg2
    5watchgod==0.7  # https://github.com/samuelcolvin/watchgod
    6
    7# Testing
    8# ------------------------------------------------------------------------------
    9mypy==0.910  # https://github.com/python/mypy
    10django-stubs==1.8.0  # https://github.com/typeddjango/django-stubs
    11pytest==6.2.5  # https://github.com/pytest-dev/pytest
    12pytest-sugar==0.9.4  # https://github.com/Frozenball/pytest-sugar
    13djangorestframework-stubs==1.4.0  # https://github.com/typeddjango/djangorestframework-stubs
    14
    15# Documentation
    16# ------------------------------------------------------------------------------
    17sphinx==4.2.0  # https://github.com/sphinx-doc/sphinx
    18sphinx-autobuild==2021.3.14 # https://github.com/GaretJax/sphinx-autobuild
    19
    20# Code quality
    21# ------------------------------------------------------------------------------
    22flake8==3.9.2  # https://github.com/PyCQA/flake8
    23flake8-isort==4.0.0  # https://github.com/gforcada/flake8-isort
    24coverage==6.0.2  # https://github.com/nedbat/coveragepy
    25black==21.9b0  # https://github.com/psf/black
    26pylint-django==2.4.4  # https://github.com/PyCQA/pylint-django
    27pylint-celery==0.3  # https://github.com/PyCQA/pylint-celery
    28pre-commit==2.15.0  # https://github.com/pre-commit/pre-commit
    29
    30# Django
    31# ------------------------------------------------------------------------------
    32factory-boy==3.2.0  # https://github.com/FactoryBoy/factory_boy
    33
    34django-debug-toolbar==3.2.2  # https://github.com/jazzband/django-debug-toolbar
    35django-extensions==3.1.3  # https://github.com/django-extensions/django-extensions
    36django-coverage-plugin==2.0.1  # https://github.com/nedbat/django_coverage_plugin
    37pytest-django==4.4.0  # https://github.com/pytest-dev/pytest-django
    38pytest==6.2.5  
    39pytest-sugar==0.9.4  
    40pytest-django==4.4.0  
    41

    Actual output

    1
    2Werkzeug==2.0.2 # https://github.com/pallets/werkzeug
    3ipdb==0.13.9  # https://github.com/gotcha/ipdb
    4psycopg2==2.9.1  # https://github.com/psycopg/psycopg2
    5watchgod==0.7  # https://github.com/samuelcolvin/watchgod
    6
    7# Testing
    8# ------------------------------------------------------------------------------
    9mypy==0.910  # https://github.com/python/mypy
    10django-stubs==1.8.0  # https://github.com/typeddjango/django-stubs
    11pytest==6.2.5  # https://github.com/pytest-dev/pytest
    12pytest-sugar==0.9.4  # https://github.com/Frozenball/pytest-sugar
    13djangorestframework-stubs==1.4.0  # https://github.com/typeddjango/djangorestframework-stubs
    14
    15# Documentation
    16# ------------------------------------------------------------------------------
    17sphinx==4.2.0  # https://github.com/sphinx-doc/sphinx
    18sphinx-autobuild==2021.3.14 # https://github.com/GaretJax/sphinx-autobuild
    19
    20# Code quality
    21# ------------------------------------------------------------------------------
    22flake8==3.9.2  # https://github.com/PyCQA/flake8
    23flake8-isort==4.0.0  # https://github.com/gforcada/flake8-isort
    24coverage==6.0.2  # https://github.com/nedbat/coveragepy
    25black==21.9b0  # https://github.com/psf/black
    26pylint-django==2.4.4  # https://github.com/PyCQA/pylint-django
    27pylint-celery==0.3  # https://github.com/PyCQA/pylint-celery
    28pre-commit==2.15.0  # https://github.com/pre-commit/pre-commit
    29
    30# Django
    31# ------------------------------------------------------------------------------
    32factory-boy==3.2.0  # https://github.com/FactoryBoy/factory_boy
    33
    34django-debug-toolbar==3.2.2  # https://github.com/jazzband/django-debug-toolbar
    35django-extensions==3.1.3  # https://github.com/django-extensions/django-extensions
    36django-coverage-plugin==2.0.1  # https://github.com/nedbat/django_coverage_plugin
    37pytest-django==4.4.0  # https://github.com/pytest-dev/pytest-django
    38pytest==6.2.5  
    39pytest-sugar==0.9.4  
    40pytest-django==4.4.0  
    41pytest==6.2.5   https://github.com/pytest-dev/pytest
    42pytest-sugar==0.9.4   https://github.com/Frozenball/pytest-sugar
    43pytest-django==4.4.0   https://github.com/pytest-dev/pytest-django
    44

    Any help to get the expected?

    These refs have not helped solve this particular problem

    ANSWER

    Answered 2022-Jan-14 at 10:30

    Using sed:

    1
    2Werkzeug==2.0.2 # https://github.com/pallets/werkzeug
    3ipdb==0.13.9  # https://github.com/gotcha/ipdb
    4psycopg2==2.9.1  # https://github.com/psycopg/psycopg2
    5watchgod==0.7  # https://github.com/samuelcolvin/watchgod
    6
    7# Testing
    8# ------------------------------------------------------------------------------
    9mypy==0.910  # https://github.com/python/mypy
    10django-stubs==1.8.0  # https://github.com/typeddjango/django-stubs
    11pytest==6.2.5  # https://github.com/pytest-dev/pytest
    12pytest-sugar==0.9.4  # https://github.com/Frozenball/pytest-sugar
    13djangorestframework-stubs==1.4.0  # https://github.com/typeddjango/djangorestframework-stubs
    14
    15# Documentation
    16# ------------------------------------------------------------------------------
    17sphinx==4.2.0  # https://github.com/sphinx-doc/sphinx
    18sphinx-autobuild==2021.3.14 # https://github.com/GaretJax/sphinx-autobuild
    19
    20# Code quality
    21# ------------------------------------------------------------------------------
    22flake8==3.9.2  # https://github.com/PyCQA/flake8
    23flake8-isort==4.0.0  # https://github.com/gforcada/flake8-isort
    24coverage==6.0.2  # https://github.com/nedbat/coveragepy
    25black==21.9b0  # https://github.com/psf/black
    26pylint-django==2.4.4  # https://github.com/PyCQA/pylint-django
    27pylint-celery==0.3  # https://github.com/PyCQA/pylint-celery
    28pre-commit==2.15.0  # https://github.com/pre-commit/pre-commit
    29
    30# Django
    31# ------------------------------------------------------------------------------
    32factory-boy==3.2.0  # https://github.com/FactoryBoy/factory_boy
    33
    34django-debug-toolbar==3.2.2  # https://github.com/jazzband/django-debug-toolbar
    35django-extensions==3.1.3  # https://github.com/django-extensions/django-extensions
    36django-coverage-plugin==2.0.1  # https://github.com/nedbat/django_coverage_plugin
    37pytest-django==4.4.0  # https://github.com/pytest-dev/pytest-django
    38pytest==6.2.5  
    39pytest-sugar==0.9.4  
    40pytest-django==4.4.0  
    41pytest==6.2.5   https://github.com/pytest-dev/pytest
    42pytest-sugar==0.9.4   https://github.com/Frozenball/pytest-sugar
    43pytest-django==4.4.0   https://github.com/pytest-dev/pytest-django
    44sed -nE 's/^(pytest[^=]*=[^[:blank:]]*).*/\1/p' file
    45
    46pytest==6.2.5
    47pytest-sugar==0.9.4
    48pytest-django==4.4.0
    49

    However a grep -o solution would be even simpler:

    1
    2Werkzeug==2.0.2 # https://github.com/pallets/werkzeug
    3ipdb==0.13.9  # https://github.com/gotcha/ipdb
    4psycopg2==2.9.1  # https://github.com/psycopg/psycopg2
    5watchgod==0.7  # https://github.com/samuelcolvin/watchgod
    6
    7# Testing
    8# ------------------------------------------------------------------------------
    9mypy==0.910  # https://github.com/python/mypy
    10django-stubs==1.8.0  # https://github.com/typeddjango/django-stubs
    11pytest==6.2.5  # https://github.com/pytest-dev/pytest
    12pytest-sugar==0.9.4  # https://github.com/Frozenball/pytest-sugar
    13djangorestframework-stubs==1.4.0  # https://github.com/typeddjango/djangorestframework-stubs
    14
    15# Documentation
    16# ------------------------------------------------------------------------------
    17sphinx==4.2.0  # https://github.com/sphinx-doc/sphinx
    18sphinx-autobuild==2021.3.14 # https://github.com/GaretJax/sphinx-autobuild
    19
    20# Code quality
    21# ------------------------------------------------------------------------------
    22flake8==3.9.2  # https://github.com/PyCQA/flake8
    23flake8-isort==4.0.0  # https://github.com/gforcada/flake8-isort
    24coverage==6.0.2  # https://github.com/nedbat/coveragepy
    25black==21.9b0  # https://github.com/psf/black
    26pylint-django==2.4.4  # https://github.com/PyCQA/pylint-django
    27pylint-celery==0.3  # https://github.com/PyCQA/pylint-celery
    28pre-commit==2.15.0  # https://github.com/pre-commit/pre-commit
    29
    30# Django
    31# ------------------------------------------------------------------------------
    32factory-boy==3.2.0  # https://github.com/FactoryBoy/factory_boy
    33
    34django-debug-toolbar==3.2.2  # https://github.com/jazzband/django-debug-toolbar
    35django-extensions==3.1.3  # https://github.com/django-extensions/django-extensions
    36django-coverage-plugin==2.0.1  # https://github.com/nedbat/django_coverage_plugin
    37pytest-django==4.4.0  # https://github.com/pytest-dev/pytest-django
    38pytest==6.2.5  
    39pytest-sugar==0.9.4  
    40pytest-django==4.4.0  
    41pytest==6.2.5   https://github.com/pytest-dev/pytest
    42pytest-sugar==0.9.4   https://github.com/Frozenball/pytest-sugar
    43pytest-django==4.4.0   https://github.com/pytest-dev/pytest-django
    44sed -nE 's/^(pytest[^=]*=[^[:blank:]]*).*/\1/p' file
    45
    46pytest==6.2.5
    47pytest-sugar==0.9.4
    48pytest-django==4.4.0
    49grep -o '^pytest[^=]*=[^[:blank:]]*' file
    50
    51pytest==6.2.5
    52pytest-sugar==0.9.4
    53pytest-django==4.4.0
    54

    Explanation:

    • ^pytest: Match pytest at the start
    • [^=]*: Match 0 or more of any character except =
    • =: Match a =
    • [^[:blank:]]*: Match 0 or more of non-whitespace characters

    Source https://stackoverflow.com/questions/70709008

    QUESTION

    CodeClimate Not reading configuration

    Asked 2021-Dec-29 at 22:54

    In my react project the code quality checker CodeClimate, using advanced configuration just stop some silly code quality factors/thresholds like 50 line of code, :

    1Function `AutocompleteCombobox` has 50 lines of code (exceeds 25 allowed). Consider refactoring.
    2

    what I did I create .codeclimate.yml besides my package.json and upload that to the repo (connected with CodeClimate on branch DEV), following documentation.

    this is the example of the .yml file:

    1Function `AutocompleteCombobox` has 50 lines of code (exceeds 25 allowed). Consider refactoring.
    2version: "2"         # required to adjust maintainability checks
    3
    4checks:
    5  argument-count:
    6    enabled: true
    7    config:
    8      threshold: 4
    9  complex-logic:
    10    enabled: true
    11    config:
    12      threshold: 4
    13
    14

    The Question is: CodeClimate doesn’t changes the records and metrics based on my configuration file!! I CHANGED THE RECORDS via .yml file; but still not updated on CodeClimate website ?!! the metrics are same as default.

    *** TIP: Nothing to do from CodeClimate website settings we stop every condition, nothing apply except default! and I don’t want to delete and re-add the repo's because I'ill lose my tracking records in enhancement.

    ANSWER

    Answered 2021-Dec-29 at 22:54

    The problem is simple, the server make file called .codeclimate.json because I edit the configurations via the website, but in my repo I made I file called .codeclimate.yml, when I convert the configuration from .yml to .json I override the one on the server that works perfectly.

    Example for may configuration .codeclimate.json:

    1Function `AutocompleteCombobox` has 50 lines of code (exceeds 25 allowed). Consider refactoring.
    2version: "2"         # required to adjust maintainability checks
    3
    4checks:
    5  argument-count:
    6    enabled: true
    7    config:
    8      threshold: 4
    9  complex-logic:
    10    enabled: true
    11    config:
    12      threshold: 4
    13
    14    {
    15      "version": "2",
    16      "checks": {
    17        "argument-count": {
    18          "enabled": false,
    19          "config": {
    20            "threshold": 4
    21          }
    22        },
    23        "complex-logic": {
    24          "enabled": true,
    25          "config": {
    26            "threshold": 15
    27          }
    28        },
    29        "file-lines": {
    30          "enabled": false,
    31          "config": {
    32            "threshold": 250
    33          }
    34        },
    35        "method-complexity": {
    36          "enabled": true,
    37          "config": {
    38            "threshold": 15
    39          }
    40        },
    41        "method-count": {
    42          "enabled": false,
    43          "config": {
    44            "threshold": 20
    45          }
    46        },
    47        "method-lines": {
    48          "enabled": false,
    49          "config": {
    50            "threshold": 25
    51          }
    52        },
    53        "nested-control-flow": {
    54          "enabled": true,
    55          "config": {
    56            "threshold": 4
    57          }
    58        },
    59        "return-statements": {
    60          "enabled": true,
    61          "config": {
    62            "threshold": 4
    63          }
    64        },
    65        "similar-code": {
    66          "enabled": false,
    67          "config": {
    68            "threshold": null
    69          }
    70        },
    71        "identical-code": {
    72          "enabled": true,
    73          "config": {
    74            "threshold": null
    75          }
    76        }
    77      },
    78      "exclude_patterns": [
    79        "config/",
    80        "db/",
    81        "dist/",
    82        "features/",
    83        "**/node_modules/",
    84        "script/",
    85        "**/spec/",
    86        "**/test/",
    87        "**/tests/",
    88        "Tests/",
    89        "**/vendor/",
    90        "**/*_test.go",
    91        "**/*.d.ts"
    92      ]
    93    }
    94

    If you face the same issue probably the configuration is duplicated on CodeClimate, you need to use one file only.

    enter image description here

    Source https://stackoverflow.com/questions/70508645

    QUESTION

    Rust compiler not optimising lzcnt? (and similar functions)

    Asked 2021-Dec-26 at 01:56
    What was done:

    This follows as a result of experimenting on Compiler Explorer as to ascertain the compiler's (rustc's) behaviour when it comes to the log2()/leading_zeros() and similar functions. I came across this result with seems exceedingly both bizarre and concerning:

    Compiler Explorer link

    Code:

    1pub fn lzcnt0(val: u64) -> u64 {
    2    val.leading_zeros() as u64
    3}
    4
    5pub unsafe fn lzcnt1(val: u64) -> u64 {
    6    core::arch::x86_64::_lzcnt_u64(val)
    7}
    8
    9pub unsafe fn lzcnt2(val: u64) -> u64 {
    10    asm_lzcnt(val)
    11}
    12
    13#[inline]
    14pub unsafe fn asm_lzcnt(val: u64) -> u64 {
    15    let lzcnt: u64;
    16    core::arch::asm!("lzcnt {}, {}", in(reg) val, lateout(reg) lzcnt, options(nomem, nostack));
    17    lzcnt
    18}
    19

    Output:

    1pub fn lzcnt0(val: u64) -> u64 {
    2    val.leading_zeros() as u64
    3}
    4
    5pub unsafe fn lzcnt1(val: u64) -> u64 {
    6    core::arch::x86_64::_lzcnt_u64(val)
    7}
    8
    9pub unsafe fn lzcnt2(val: u64) -> u64 {
    10    asm_lzcnt(val)
    11}
    12
    13#[inline]
    14pub unsafe fn asm_lzcnt(val: u64) -> u64 {
    15    let lzcnt: u64;
    16    core::arch::asm!("lzcnt {}, {}", in(reg) val, lateout(reg) lzcnt, options(nomem, nostack));
    17    lzcnt
    18}
    19example::lzcnt0:
    20        test    rdi, rdi
    21        je      .LBB0_2
    22        bsr     rax, rdi
    23        xor     rax, 63
    24        ret
    25.LBB0_2:
    26        mov     eax, 64
    27        ret
    28
    29example::lzcnt1:
    30        jmp     core::core_arch::x86_64::abm::_lzcnt_u64
    31
    32core::core_arch::x86_64::abm::_lzcnt_u64:
    33        lzcnt   rax, rdi
    34        ret
    35
    36example::lzcnt2:
    37        lzcnt   rdi, rax
    38        ret
    39
    40

    The compiler options are to best emulate cargo's 'release' configuration (with opt-level=3 for good measure), and otherwise trying my best to get the compiler to optimise the functions. The specific target shouldn't matter, as long as it targets x86-64, I've tried x86_64-{pc-windows-{msvc,gnu},unknown-linux-gnu}.

    What was expected:

    All of these outputs should be identical to lzcnt2. Instruction Performance Tables lzcnt is evidently a fast instruction across the board and should be used, and having an unnecessary branch in such a low level function is dismal. What's weirder, the function _lzcnt_u64() calls leading_zeros() under the hood - which the compiler is happy to magic away (there's no checks or asserts either), but won't seem to do it for the underlying function. What's more, the compiler won't inline the lzcnt instruction even in that case? (the implementation marks the function a #[inline] too) Sure, a jmp isn't as bad, but it's entirely unnecessary as should be avoided.

    What it could be:
    • Compiler bug?
    • Purposeful choice I don't understand?
    • I don't understand how to use Compiler Explorer properly?
    • Other?

    I'm seeing similar results in functions like log2 and (I presume) others that rely on the ctlz rust compiler intrinsic in their implementation.

    If you understand compilers sufficiently, any clarification would be greatly appreciated. I don't fancy writing loads of utility functions for little reason, but I'll do so if there's no better alternative.

    P.S. If your answer is along the lines of that the performance gain is negligible in most situations, and/or that I shouldn't care due to code quality or similar reasoning: I understand the sentiment, but that's not the point of this question. I'm writing for bare-metal, hot code in a personal project.

    ANSWER

    Answered 2021-Dec-26 at 01:56

    Old x86-64 CPUs don't support lzcnt, so rustc/llvm won't emit it by default. (They would execute it as bsr but the behavior is not identical.)

    Use -C target-feature=+lzcnt to enable it. Try.

    More generally, you may wish to use -C target-cpu=XXX to enable all the features of a specific CPU model. Use rustc --print target-cpus for a list.

    In particular, -C target-cpu=native will generate code for the CPU that rustc itself is running on, e.g. if you will run the code on the same machine where you are compiling it.

    Source https://stackoverflow.com/questions/70481312

    QUESTION

    Gitlab-CI: Nodejs application fails to build

    Asked 2021-Dec-20 at 11:58

    I am using gitlab-ci to build a react application but the build stage always fails, on my local machine it works fine same thing on my deployment server but when using gitlab-ci it fails with

    1 Line 421:34:   Expected '===' and instead saw '=='                     eqeqeq
    2  Line 473:13:   'names' is assigned a value but never used              no-unused-vars
    3  Line 789:96:   Expected '!==' and instead saw '!='                     eqeqeq
    4  Line 792:182:  Expected '!==' and instead saw '!='                     eqeqeq
    5  Line 792:258:  Expected '!==' and instead saw '!='                     eqeqeq
    6  Line 792:295:  Expected '!==' and instead saw '!='                     eqeqeq
    7  Line 793:161:  Expected '!==' and instead saw '!='                     eqeqeq
    8  Line 793:236:  Expected '!==' and instead saw '!='                     eqeqeq
    9  Line 793:272:  Expected '!==' and instead saw '!='                     eqeqeq
    10  Line 813:203:  Style prop value must be an object                      react/style-prop-object
    11./src/components/login.component.js
    12  Line 9:7:    'user' is assigned a value but never used                no-unused-vars
    13  Line 73:13:  'currentUser' is assigned a value but never used         no-unused-vars
    14  Line 73:26:  'showModeratorBoard' is assigned a value but never used  no-unused-vars
    15  Line 73:46:  'showAdminBoard' is assigned a value but never used      no-unused-vars
    16  Line 73:63:  'SuperAdmin' is assigned a value but never used          no-unused-vars
    17  Line 73:77:  'showAdminDirect' is assigned a value but never used     no-unused-vars
    18npm ERR! code ELIFECYCLE
    19npm ERR! errno 1
    20npm ERR! react-jwt-auth@0.1.0 build: `react-scripts build`
    21npm ERR! Exit status 1
    22npm ERR! 
    23npm ERR! Failed at the react-jwt-auth@0.1.0 build script.
    24npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
    25npm ERR! A complete log of this run can be found in:
    26npm ERR!     /builds/tahar.benachour/endarh/.npm/_logs/2021-11-23T12_31_40_565Z-debug.log
    27Cleaning up file based variables
    2800:01
    29ERROR: Job failed: exit code 1
    30

    I tried different images but same error

    my gitlab-ci.yml

    1 Line 421:34:   Expected '===' and instead saw '=='                     eqeqeq
    2  Line 473:13:   'names' is assigned a value but never used              no-unused-vars
    3  Line 789:96:   Expected '!==' and instead saw '!='                     eqeqeq
    4  Line 792:182:  Expected '!==' and instead saw '!='                     eqeqeq
    5  Line 792:258:  Expected '!==' and instead saw '!='                     eqeqeq
    6  Line 792:295:  Expected '!==' and instead saw '!='                     eqeqeq
    7  Line 793:161:  Expected '!==' and instead saw '!='                     eqeqeq
    8  Line 793:236:  Expected '!==' and instead saw '!='                     eqeqeq
    9  Line 793:272:  Expected '!==' and instead saw '!='                     eqeqeq
    10  Line 813:203:  Style prop value must be an object                      react/style-prop-object
    11./src/components/login.component.js
    12  Line 9:7:    'user' is assigned a value but never used                no-unused-vars
    13  Line 73:13:  'currentUser' is assigned a value but never used         no-unused-vars
    14  Line 73:26:  'showModeratorBoard' is assigned a value but never used  no-unused-vars
    15  Line 73:46:  'showAdminBoard' is assigned a value but never used      no-unused-vars
    16  Line 73:63:  'SuperAdmin' is assigned a value but never used          no-unused-vars
    17  Line 73:77:  'showAdminDirect' is assigned a value but never used     no-unused-vars
    18npm ERR! code ELIFECYCLE
    19npm ERR! errno 1
    20npm ERR! react-jwt-auth@0.1.0 build: `react-scripts build`
    21npm ERR! Exit status 1
    22npm ERR! 
    23npm ERR! Failed at the react-jwt-auth@0.1.0 build script.
    24npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
    25npm ERR! A complete log of this run can be found in:
    26npm ERR!     /builds/tahar.benachour/endarh/.npm/_logs/2021-11-23T12_31_40_565Z-debug.log
    27Cleaning up file based variables
    2800:01
    29ERROR: Job failed: exit code 1
    30stages:
    31  - setup
    32  - build
    33  - deployment
    34
    35variables:
    36  npm_config_cache: "$CI_PROJECT_DIR/.npm"
    37
    38image: node:10
    39
    40# This folder is cached between builds
    41.dependencies_cache:
    42  cache:
    43    key:
    44      files:
    45        - package-lock.json # A transformer en package-lock.json
    46    paths:
    47      - .npm
    48    policy: pull
    49
    50app-setup:
    51  stage: setup
    52  script:
    53    - npm ci
    54    - npm run build
    55  extends: .dependencies_cache
    56  cache:
    57    policy: pull-push
    58  artifacts:
    59    expire_in: 2h
    60    paths:
    61      - .npm
    62      - build/
    63

    Some additional details, I saved logs and build directory as artifact here is the log details

    1 Line 421:34:   Expected '===' and instead saw '=='                     eqeqeq
    2  Line 473:13:   'names' is assigned a value but never used              no-unused-vars
    3  Line 789:96:   Expected '!==' and instead saw '!='                     eqeqeq
    4  Line 792:182:  Expected '!==' and instead saw '!='                     eqeqeq
    5  Line 792:258:  Expected '!==' and instead saw '!='                     eqeqeq
    6  Line 792:295:  Expected '!==' and instead saw '!='                     eqeqeq
    7  Line 793:161:  Expected '!==' and instead saw '!='                     eqeqeq
    8  Line 793:236:  Expected '!==' and instead saw '!='                     eqeqeq
    9  Line 793:272:  Expected '!==' and instead saw '!='                     eqeqeq
    10  Line 813:203:  Style prop value must be an object                      react/style-prop-object
    11./src/components/login.component.js
    12  Line 9:7:    'user' is assigned a value but never used                no-unused-vars
    13  Line 73:13:  'currentUser' is assigned a value but never used         no-unused-vars
    14  Line 73:26:  'showModeratorBoard' is assigned a value but never used  no-unused-vars
    15  Line 73:46:  'showAdminBoard' is assigned a value but never used      no-unused-vars
    16  Line 73:63:  'SuperAdmin' is assigned a value but never used          no-unused-vars
    17  Line 73:77:  'showAdminDirect' is assigned a value but never used     no-unused-vars
    18npm ERR! code ELIFECYCLE
    19npm ERR! errno 1
    20npm ERR! react-jwt-auth@0.1.0 build: `react-scripts build`
    21npm ERR! Exit status 1
    22npm ERR! 
    23npm ERR! Failed at the react-jwt-auth@0.1.0 build script.
    24npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
    25npm ERR! A complete log of this run can be found in:
    26npm ERR!     /builds/tahar.benachour/endarh/.npm/_logs/2021-11-23T12_31_40_565Z-debug.log
    27Cleaning up file based variables
    2800:01
    29ERROR: Job failed: exit code 1
    30stages:
    31  - setup
    32  - build
    33  - deployment
    34
    35variables:
    36  npm_config_cache: "$CI_PROJECT_DIR/.npm"
    37
    38image: node:10
    39
    40# This folder is cached between builds
    41.dependencies_cache:
    42  cache:
    43    key:
    44      files:
    45        - package-lock.json # A transformer en package-lock.json
    46    paths:
    47      - .npm
    48    policy: pull
    49
    50app-setup:
    51  stage: setup
    52  script:
    53    - npm ci
    54    - npm run build
    55  extends: .dependencies_cache
    56  cache:
    57    policy: pull-push
    58  artifacts:
    59    expire_in: 2h
    60    paths:
    61      - .npm
    62      - build/
    630 info it worked if it ends with ok
    641 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'build' ]
    652 info using npm@6.14.12
    663 info using node@v10.24.1
    674 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
    685 info lifecycle react-jwt-auth@0.1.0~prebuild: react-jwt-auth@0.1.0
    696 info lifecycle react-jwt-auth@0.1.0~build: react-jwt-auth@0.1.0
    707 verbose lifecycle react-jwt-auth@0.1.0~build: unsafe-perm in lifecycle true
    718 verbose lifecycle react-jwt-auth@0.1.0~build: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/builds/tahar.benachour/endarh/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    729 verbose lifecycle react-jwt-auth@0.1.0~build: CWD: /builds/tahar.benachour/endarh
    7310 silly lifecycle react-jwt-auth@0.1.0~build: Args: [ '-c', 'react-scripts build' ]
    7411 silly lifecycle react-jwt-auth@0.1.0~build: Returned: code: 1  signal: null
    7512 info lifecycle react-jwt-auth@0.1.0~build: Failed to exec build script
    7613 verbose stack Error: react-jwt-auth@0.1.0 build: `react-scripts build`
    7713 verbose stack Exit status 1
    7813 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
    7913 verbose stack     at EventEmitter.emit (events.js:198:13)
    8013 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
    8113 verbose stack     at ChildProcess.emit (events.js:198:13)
    8213 verbose stack     at maybeClose (internal/child_process.js:982:16)
    8313 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
    8414 verbose pkgid react-jwt-auth@0.1.0
    8515 verbose cwd /builds/tahar.benachour/endarh
    8616 verbose Linux 5.4.0-90-generic
    8717 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
    8818 verbose node v10.24.1
    8919 verbose npm  v6.14.12
    9020 error code ELIFECYCLE
    9121 error errno 1
    9222 error react-jwt-auth@0.1.0 build: `react-scripts build`
    9322 error Exit status 1
    9423 error Failed at the react-jwt-auth@0.1.0 build script.
    9523 error This is probably not a problem with npm. There is likely additional logging output above.
    9624 verbose exit [ 1, true ]
    97

    the build directory and files are created successfully and it runs fine on my web server so to be honest I don't understand the pipeline failure perhaps as said related to lint and code quality

    ANSWER

    Answered 2021-Nov-23 at 12:46

    Those are linter errors. Check the npm scripts that are being executed (probabaly on npm run build) as this is probably running your linter and producing the errors.

    I would suggest you run the same thing locally and fix those :)

    This doesn't look related to GitLab at all

    Source https://stackoverflow.com/questions/70081139

    Community Discussions contain sources that include Stack Exchange Network

    Tutorials and Learning Resources in Code Quality

    Tutorials and Learning Resources are not available at this moment for Code Quality

    Share this Page

    share link

    Get latest updates on Code Quality