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

standard

eslint

dnSpy

v6.1.8

tools

v0.4.2

Popular Libraries in Code Quality

javascript

by airbnb doticonjavascriptdoticon

star image 118201 doticonMIT

JavaScript Style Guide

prettier

by prettier doticonjavascriptdoticon

star image 42446 doticonMIT

Prettier is an opinionated code formatter.

x64dbg

by x64dbg doticonc++doticon

star image 37297 doticonGPL-3.0

An open-source x64/x32 debugger for windows.

standard

by standard doticonjavascriptdoticon

star image 26892 doticonMIT

🌟 JavaScript Style Guide, with linter & automatic code fixer

eslint

by eslint doticonjavascriptdoticon

star image 20402 doticonMIT

Find and fix problems in your JavaScript code.

dnSpy

by dnSpy doticoncsharpdoticon

star image 18900 doticon

.NET debugger and assembly editor

tools

by rome doticonrustdoticon

star image 18488 doticonMIT

The Rome Toolchain. A linter, compiler, bundler, and more for JavaScript, TypeScript, HTML, Markdown, and CSS.

delve

by go-delve doticongodoticon

star image 18048 doticonMIT

Delve is a debugger for the Go programming language.

PySnooper

by cool-RR doticonpythondoticon

star image 14960 doticonMIT

Never use print for debugging again

Trending New libraries in Code Quality

tools

by rome doticonrustdoticon

star image 18488 doticonMIT

The Rome Toolchain. A linter, compiler, bundler, and more for JavaScript, TypeScript, HTML, Markdown, and CSS.

ProcMon-for-Linux

by Sysinternals doticonc++doticon

star image 3077 doticonMIT

Procmon is a Linux reimagining of the classic Procmon tool from the Sysinternals suite of tools for Windows. Procmon provides a convenient and efficient way for Linux developers to trace the syscall activity on the system.

Ryven

by leon-thomm doticonpythondoticon

star image 2490 doticonMIT

Flow-based visual scripting for Python

Cyberbrain

by laike9m doticonpythondoticon

star image 2020 doticonMIT

Python debugging, redefined.

gokart

by praetorian-inc doticongodoticon

star image 1922 doticonApache-2.0

A static analysis tool for securing Go code

viztracer

by gaogaotiantian doticonpythondoticon

star image 1788 doticonApache-2.0

VizTracer is a low-overhead logging/debugging/profiling tool that can trace and visualize your python code execution.

Drawflow

by jerosoler doticonjavascriptdoticon

star image 1546 doticonMIT

Simple flow library 🖥️🖱️

rslint

by rslint doticonrustdoticon

star image 1516 doticonMIT

A (WIP) Extremely fast JavaScript and TypeScript linter and Rust crate

FGVC

by vt-vl-lab doticonpythondoticon

star image 1268 doticonNOASSERTION

[ECCV 2020] Flow-edge Guided Video Completion

Top Authors in Code Quality

1

AtomLinter

48 Libraries

star icon1825

2

SublimeLinter

40 Libraries

star icon4685

3

microsoft

39 Libraries

star icon20609

4

codacy

29 Libraries

star icon451

5

sindresorhus

24 Libraries

star icon11712

6

google

24 Libraries

star icon32363

7

jonschlinkert

19 Libraries

star icon226

8

jenkinsci

16 Libraries

star icon649

9

standard

16 Libraries

star icon30891

10

jfmengels

15 Libraries

star icon357

1

48 Libraries

star icon1825

2

40 Libraries

star icon4685

3

39 Libraries

star icon20609

4

29 Libraries

star icon451

5

24 Libraries

star icon11712

6

24 Libraries

star icon32363

7

19 Libraries

star icon226

8

16 Libraries

star icon649

9

16 Libraries

star icon30891

10

15 Libraries

star icon357

Trending Kits in Code Quality

PHP is a popular open-source programming language that is widely used for developing web applications. It helps developers to create dynamic content for websites and mobile apps. PHP Testing is one of the most important parts of PHP development. It allows you to test your code, check the performance of your product, and find bugs. The best PHP testing tools allow developers to run tests in a simple way, from unit tests to functional testing. To make your life easier, we’ve prepared a list of 7 best PHP Testing Open Source libraries in 2022 in our kit, laravel-generator - CRUD Laravel Generator; php-quickcheck - generative testing for PHP; phpunit-skeleton-generator - generate skeleton test classes from production code classes.

Build robotics, collect machine data, fun projects, and more with these Python microcontroller libraries.

 

Using microcontroller libraries is one of the most efficient ways of implementing Python in microcontrollers. With these libraries you can not only add machine learning capabilities to your project but also add support for real-time operating systems such as Zephyr. Popular Python microcontroller libraries like MicroPython provide implementation of several components that consists of an array, collections, errno, binascii, builtins, cmath, gc, json, math, hashlib, heapq, io, os, select, socket, ssl, random, re, uasyncio, zlib, struct, sys, time, and _thread. It is an open-source firmware solution designed to help developers implement the features of high-level language offered by Python into low-level hardware platforms and microcontrollers. Also, these libraries can run on small memory systems.


Explore below the list of top and trending Python microcontroller libraries to include in your machine learning or robotics project.

platformio-core:  

  •  Platform IO Core is an open-source ecosystem for developing Internet of Things.    
  •  Platform IO Core is available for Windows, macOS, and Linux.   
  •  Platform IO Core supports a wide range of development platforms and microcontrollers. 

stm32-rs:  

  •  "stm32-rs" likely refers to a Rust programming library for working with STM32 microcontrollers.  
  • STM32 is a family of microcontrollers developed by STMicroelectronics.  
  •  Rust is a programming language known for its system-level programming, and safety.    

pyOCD :  

  • PyOCD is an open-source Python tool for programming and debugging ARM Cortex-M microcontrollers.  
  • PyOCD supports a wide range of development boards and debug probes.   
  • PyOCD helps to program firmware onto ARM Cortex-M microcontrollers.   

pyOCD :  

  • PyOCD works with a wide range of development boards and debug probes. 
  • PyOCD supports a wide range of development boards and debug probes.   
  • PyOCD helps to program firmware onto ARM Cortex-M microcontrollers.   

Python-Arduino-Command-API:  

  •  Python-Arduino-Command-API is a Python library that provides a convenient and user-friendly way.   
  •  This library simplifies sending and receiving data between a Python script.  
  •   It makes it easier to develop projects that involve Arduino in a Python environment. 

goodfet:  

  • GoodFET is an open-source, open-hardware project.  
  •  That aims to create a flexible and affordable hardware tool for embedded systems.   
  •  It helps to facilitate various tasks related to embedded systems. 

stcflash:  

  • stcflash is a Python library typically used in Internet of Things (IoT) applications.   
  • STC microcontrollers chip produced by STC Microelectronics, a Chinese semiconductor company.  
  •  It can helps to load your own code onto the microcontroller or to update existing firmware.   

emlearn:  

  • emlearn is an open-source project focused on deploying machine learning models on resource-constrained.  
  • emlearn enables developers to use machine learning techniques on microcontrollers.  
  • emlearn provides tools and libraries to convert ML models trained with popular frameworks.

lib-python:  

  •  Lib-python likely refers to the standard library of the Python programming language.  
  • These modules come bundled with Python and helps in your Python program.  
  • Python's standard library is a comprehensive collection of modules and packages. It provides a range of functionality for various tasks.    

illuminOS:  

  • illuminOS is a Python library used in IoT, and Arduino applications.  
  • illuminOS has no bugs, it has no vulnerabilities.  
  •  An open-source Micro Python-based OS for ESP microcontroller variants.  

LEMPA:  

  •  It refers to a language proficiency exam in the Lithuanian language.   
  • It is often required for individuals who want to study or work in Lithuania. It helps to demonstrate proficiency in the Lithuanian language.   
  •  LEMPA could be an acronym for various phrases or organizations.

KiCad-Schematic-Symbol-Libraries:  

  • KiCad-Schematic-Symbol-Libraries refers to the collection of schematic symbol libraries used in KiCad.  
  • It is an open-source electronic design automation (EDA) suite.  
  • KiCad helps in designing electronic circuits and printed circuit boards (PCBs).  

FAQ 

1. What are Python microcontroller libraries?  

Python microcontroller libraries are software packages or modules that enable Python. which has small, self-contained computing devices often used in embedded systems. These libraries provide a high-level interface for programming microcontrollers, making it easy.   

 

2. Why use Python for microcontrollers?  

Python, known for its simplicity, is a popular and high-level programming language. Using Python on microcontrollers simplifies development and reduces the learning curve. It allows for rapid prototyping and development of embedded systems.   

 

3. Which microcontroller platforms are supported by Python microcontroller libraries?   

Python microcontroller libraries support a variety of microcontroller platforms. It includes popular ones like Arduino, Raspberry Pi, ESP8266, ESP32, and more. The availability of libraries may vary depending on the platform.   

 

4. Are Python microcontroller libraries open source?  

Many Python microcontroller libraries are open source, which means their source code. It modifies and contributes to the developer community. Open-source libraries encourage collaboration and innovation.   

 

5. What functionalities do Python microcontroller libraries offer?  

Python microcontroller libraries provide functions for tasks such as 

1. digital and analog I/O,  

2. sensor data acquisition,  

3. communication (UART, SPI, I2C),  

4. PWM control, and  

5. interfacing with displays.  

Some libraries also support networking and Internet of Things (IoT) functionality.  

Here are the best PHP Static analysis libraries, which can be utilized to debug software programs that involve examining the code without running the application.  


The automatic source code analysis done without running the application is known as static analysis. Dynamic analysis refers to analysis carried out while a program is being executed. Static analysis frequently finds security flaws, performance problems, standard-compliance violations, and outdated programming structures. All static analysis tools share the fundamental idea of examining source code for coding patterns marked with a warning or other information. By customizing the static analysis tool to measure portions of the code and only report on a subset of rules, some programmers use static analysis as an objective indicator of the quality of their code.  


The top-of-the-board libraries are mentioned below to cause static analysis of PHP source code to be straightforward for developers. 

phpstan- 

  • Without running your code, PHPStan concentrates on locating problems in it.  
  • Finds entire classes of errors even before you write code tests.  
  • Brings PHP closer to compiled languages in that the validity of each line of code can be tested before running it. 

phan- 

  • Prefers to minimize false positives. 
  • Attempts to prove incorrectness rather than correctness. 
  • Can verify type compatibility on various operations. 
  • The most straightforward way to use Phan is via Composer.

psalm- 

  • Takes care of taint analysis, type inference, and security analysis.  
  • Tends to find errors in PHP applications. 
  • It helps to maintain a wide variety of codebases. 

PhpMetrics- 

  • Provides metrics about PHP projects and classes. 
  • Generates beautiful and readable HTML reports. 
  • Understandable static analysis tool. 

noverify- 

  • Can analyze changes in git and show only new reports. 
  • Has PHP 7 and PHP 8 support. 
  • It is fast and can analyze 100k LOC/s. 

PhpDependencyAnalysis- 

  • Finds violation in a dependency graph. 
  • Extendable static code analysis for object-oriented PHP-Projects. 
  • Generate dependency graph from abstract classes.

Mondrian- 

  • Uses graph theory for static analysis. 
  • Helps to add abstraction into concrete classes. 
  • The generated HTML file does not require any dependencies or a connection. 

Exakat- 

  • Smart engine for static code analysis. 
  • Automated code review is possible. 
  • Is a great review tool and an analysis framework. 

Vulny-Code-Static-Analysis- 

  • It is a python script-based static analysis tool. 
  • Works based on regular expressions or regex. 
  • Can detect vulnerabilities in PHP source code.

progpilot- 

  • A tool specialized in static analysis in security. 
  • Is possible to use progpilot inside PHP code. 
  • The taint analysis configuration is customizable. 

Here are the top Python libraries for coding assessments that you can use to check the syntax and style of the code, unit testing, functional testing, integration testing of multiple code units, performance testing of code, security testing, and user acceptance testing. These assessments can be carried out simultaneously to ensure that the code is accurate, efficient, secure, and complies with the project's requirements.  


Coding assessment libraries are frameworks and tools for assessing the caliber and accuracy of source code. They can assist developers in identifying potential defects and problems, guarantee that code is developed according to best practices and coding standards, and that the code complies with the project's requirements and specifications. These libraries can be used for manual and automated testing and can be incorporated into the development process.  


The top Python Coding Assessment libraries are shown below. Here is a detailed review of each library. 

pytest: 

  • Provides a straightforward and adaptable API for creating and managing tests. 
  • Is a well-known testing framework that supports writing and running tests for applications. 
  • Can be used to create integration, functional, and unit tests. 

hypothesis: 

  • Creates test cases based on user-defined properties for property-based testing. 
  • May be employed to create concise, understandable tests for a variety of use cases. 
  • Provides robust testing by producing edge cases automatically and testing for unexpected behaviors. 

pycodestyle: 

  • A linting tool for comparing Python code to PEP 8 style guidelines. 
  • Can be used to check code for problems with naming conventions, indentation, and other coding style elements like whitespace. 
  • Enable customization of rules and smooth integration with various code editors and IDEs. 

pylint: 

  • A coding assessment tool that checks for potential errors, bugs, and coding style problems in Python code. 
  • Provides a collection of rules that may be customized, and it can be integrated into IDEs and development workflows. 
  • Can assist in locating and resolving coding issues before they become serious. 

vmaf: 

  • Perceptual video quality assessment library based on multi-method fusion.  
  • Includes a stand-alone C library (libvmaf) and its wrapping Python library.   
  • Offers various tools which allow users to train and test a custom VMAF Model. 

flake8: 

  • A linting tool that combines the capabilities of PyFlakes, McCabe, and PyCodeStyle. 
  • You can utilize code style, complexity, and syntax checks. 
  • Provides a simple-to-use API for integrating into continuous integration systems and development workflows. 

chipsec: 

  • Is a platform security assessment framework for analyzing the security of PC platforms like system firmware, hardware, and platform components.  
  • Includes a security test suite, forensic capabilities, and tools for accessing different low-level interfaces.  
  • Contains modules like simple tests on hardware configurations and protections, security assessment, and fuzzing tools for different platform devices and interfaces.   

drozer: 

  • Allows you to search for security vulnerabilities in devices and applications by taking up the role of an app interacting with the other apps.   
  • Provides tools for helping us to use, understand, and share public Android exploits.  
  • Helps deploy a drozer Agent to a device through social engineering or exploitation. 

archerysec: 

  • With the help of archerysec, you can Automate your application Security Orchestration and Correlation.  
  • Allows you to interact with continuous integration and delivery toolchains for specific testing and controlling the release of a given build, depending on the results.  
  • Includes prioritization functions that will enable you to focus on critical vulnerabilities.  

image-quality-assessment: 

  • Uses Convolutional Neural Networks to predict the technical quality and aesthetic of the images.  
  • Offered code will allow you to use any of the pre-trained models in Keras.  
  • Provides an implementation based on Google’s NIMA: Neural Image Assessment. 

nose: 

  • Offers plugins and extensions for advanced testing, including test generators and test discovery.  
  • Extends unittest and adds new capabilities. 
  • Can be used to create and execute tests for programs, even ones with complex testing requirements. 

Here are the best open-source Python code refactoring libraries for your applications. You can use these to improve the structure, readability, and performance of the code by automatically analyzing it and making suggested changes.


Refactoring is an important process in software development. There are various Python libraries that help improve the quality of code and make it more maintainable, scalable, and reusable. These libraries provide many features, including renaming, extracting code into functions, moving code between files, and more. With an easy-to-use interface, these integrate well with popular code editors like PyCharm, Emacs, and Vim. Also, certain libraries can detect issues such as unused variables, undefined names, and syntax errors. Most Python code refactoring libraries are highly configurable and can be customized to suit the needs of different projects.


In conclusion, Python code refactoring libraries help developers to identify and fix issues, enforce coding standards, and improve the code structure and readability. By using these tools, developers can save time, reduce errors, and create high-quality code that is easier to maintain and scale. We have handpicked the top and trending open-source Python code refactoring libraries for your next application development project:


Rope:

  • Used in Utilities, Python Refactoring, Parser applications, etc.
  • Provides various features like renaming, moving code between files, and more.
  • Supports popular code editors.

PyLint:

  • Used for checking errors and enforcing coding standards in Python code.
  • Helps detect issues such as unused variables, undefined names, and syntax errors.
  • Can be customized to match the requirements of different projects.

Black:

  • Used for enforcing consistency and readability in codebases.
  • Automatically formats Python code to conform to a specific set of style guidelines.
  • It is highly configurable and customizable as per different projects.

Refactor:

  • Used in Editor, Code Editor applications, etc.
  • Provides code analysis and refactoring tools for Python.
  • Features include renaming, extracting code into functions, and more.

Autopep8

  • Used for automatically formatting Python code to conform to PEP 8 style guidelines.
  • Helps quickly and easily reformat code.
  • Improves code readability and maintainability.

Radon:

  • Used in Code Quality, Code Analyzer applications, etc.
  • Helps identify code that is difficult to maintain, understand, or extend.
  • Provides various metrics, including cyclomatic complexity and maintainability index.

PyFlakes:

  • Used for analyzing Python code for errors and potential problems.
  • Helps identify issues such as undefined variables, unused imports, and more.
  • Supports all active versions of Python: 3.6+.

SymPy:

  • Used to perform algebraic manipulations, calculus operations, and more.
  • It’s a library for symbolic mathematics in Python.
  • Helps simplify and refactor complex mathematical expressions in code.

Pyroma:

  • Used to ensure that Python packages are well-designed and easy to use.
  • It is a tool for analyzing Python packages for quality and best practices.
  • Helps identify issues such as missing metadata, poor project structure, and more.

JavaScript number formatting libraries provide tools and functions to format, manipulate, and display numbers in a desired format. These libraries offer various features and customization options to handle number formatting tasks efficiently. Some popular JavaScript number formatting libraries include Numeral.js, accounting.js, Intl.NumberFormat (built-in JavaScript API), d3-format (part of D3.js), and numeral (a smaller alternative to Numeral.js). These libraries offer a wide range of features, and you can select the one that best fits your project's requirements in terms of functionality, ease of use, and performance. 

 

Let’s look at each library in detail. You can access package commands, installation notes, code snippets using the links below. 

Numeral-js: 

  • Numeral.js is a JavaScript library that provides a simple and powerful way to format, manipulate, and display numbers. 
  • This makes it easy to perform various manipulations on numbers, such as rounding, adding, subtracting, multiplying, and dividing, all in a single chain of method calls. 
  • It supports a wide range of formatting options, including decimals, separators, currencies, percentages, abbreviations, and more. You can easily specify the desired format using the library's API. 
  • The library supports localization, allowing you to format numbers according to different language and region settings. 

accounting.js: 

  • Accounting.js is a lightweight JavaScript library designed for number formatting, currency handling, and simple accounting operations 
  • This includes specifying the default currency symbol, currency precision (number of decimal places), and currency symbol placement (before or after the number). 
  • It provides locale-specific formatting options, such as decimal separators, thousand separators, and currency symbols. 
  • It provides functions to format numbers with decimal precision, apply thousand separators, and customize the formatting of negative numbers. 

numeric: 

  • Numeric.js provides a fluent API that allows you to chain multiple operations together. 
  • It supports formatting options such as decimals, separators (e.g., commas), currency symbols, percentages, abbreviations, and more. 
  • Numeric.js is a lightweight library with a simple and intuitive API. It is easy to include in your JavaScript projects and requires minimal setup. 
  • You can specify the desired locale or let Numeral.js automatically detect the user's browser locale. 

numbro: 

  • Numbro focuses on simplicity, performance, and internationalization, making it suitable for a wide range of number-related tasks in JavaScript applications. 
  • It supports a wide range of locales, allowing you to customize the number formatting based on specific cultural conventions. 
  • The library provides extensive localization support, enabling you to format numbers based on different language and region settings. 
  • You can define your own formatting patterns, including the number of decimal places, separators, currency symbols, and more. 

humanize: 

  • humanize-plus includes functions to humanize numbers by adding appropriate separators, abbreviations, and units. 
  • It provides capabilities for formatting large numbers, ordinal numbers, rounding numbers, and more. 
  • This is useful when presenting file size information to users, making it easier for them to understand the magnitude of file sizes. 
  • Humanize-plus provides functions to convert file sizes into a more readable format. It can format file sizes in bytes, kilobytes, megabytes, gigabytes, and beyond. 

d3-format: 

  • d3-format library is a part of the D3.js (Data-Driven Documents) ecosystem and provides a set of functions for formatting numbers, dates, and other values in a customizable way. It 
  • It supports various formatting options for displaying dates and times in different formats, including year, month, day, hour, minute, second, and more. 
  • The library provides localization support, allowing you to format numbers and dates according to different locales and language conventions. 
  • It supports scaling numbers and displaying them in a more human-readable format with prefixes like kilo (K), mega (M), giga (G), etc. This is particularly useful when working with large or small numbers. 

format-number 

  • A number formatting library in JavaScript, like "number-formatter," is designed to facilitate the formatting and manipulation of numbers in a customizable way. 
  • The library allows you to format numbers based on various criteria, such as decimal places, separators (e.g., commas), significant figures, currency symbols, percentage symbols, and more 
  • They allow you to format numbers according to different locales, language conventions, and currency formats. 
  • This can include defining custom patterns, specifying the position of symbols, choosing rounding methods, and configuring other formatting preferences. 

FAQ: 

1. What is a JavaScript number formatting library?   

A JavaScript number formatting library is a software package or tool that provides functions, methods, or utilities for formatting numbers in a desired format. It helps developers manipulate and present numerical data in a human-readable and localized manner. These libraries typically offer a range of options to customize how numbers are displayed, including decimal places, separators, currency symbols, percentage symbols, and more. 

 

2. How can I use the JavaScript Internationalization API to format currency formatted numbers?   

To format currency formatted numbers using the JavaScript Internationalization (Intl) API, you can utilize the Intl.NumberFormat object, which provides built-in support for formatting numbers according to specific locales and currency formats. By using the Intl.NumberFormat object and specifying the appropriate locale and currency options, you can format numbers as currency according to the conventions of different regions and languages. 

 

3. What is the format function used for in a number formatting library?   

The format function in a number formatting library is a core feature that allows you to transform a numerical value into a formatted string representation according to specific formatting rules and patterns. It takes a number as input and applies the desired formatting options to produce the formatted string output. 

The format function typically accepts one or more parameters, depending on the library and its specific implementation. The most common parameter is the number you want to format. It can be a numeric value, such as an integer or a floating-point number. 

 

4. How can I specify decimal values when using a number formatting library?   

When using a number formatting library, you can typically specify the decimal values by using formatting options or parameters provided by the library. The specific method for specifying decimal values may vary depending on the library you are using, but here are some common approaches: 

  • Decimal Places 
  • Rounding 
  • Truncation 

 

5. What are locale strings and how do they work for numeric formatting libraries?   

locale strings, in the context of numeric formatting libraries, are strings that represent a specific locale or language region. They are used to define the formatting rules and conventions for numbers in that particular locale. 

A locale string typically consists of two parts: a language code and a region code, separated by a hyphen. For example, "en-US" represents the English language in the United States, while "de-DE" represents German in Germany. The language code represents the primary language, and the region code represents the specific country or region associated with that language. 

When using numeric formatting libraries, you can specify a locale string as a parameter or option to indicate the desired formatting rules based on a specific locale. The library will then apply the appropriate formatting conventions for numbers in that locale, including decimal separators, thousands of separators, currency symbols, and other formatting preferences. 

Pipenv is a powerful tool for managing Python dependencies and virtual environments. The working with Pipenv, several libraries can enhance your workflow.

It makes virtual environment management and development more reproducible. 


Key features of Pipenv: 

  1. Dependency Management 
  2. Automatic Virtual Environment Creation 
  3. Pipfile and Pipfile.lock 
  4. Streamlined Workflow 
  5. Integration with PyPI 


Pipenv is a command-line tool that aims to bring the best of all packaging worlds to the Python world. It automatically creates and manages a virtual environment for your projects. It as well as adds and removes packages from Pipfile as you install and uninstall packages. 

pipenv: 

  • Pipenv is a popular tool for managing Python virtual environments in Python projects. 
  • Pipenv provides many more commands and options for managing Python projects. 
  • It includes locking dependencies to specific versions, managing development dependencies, and more. 

pyenv: 

  • Pyenv is a Python management tool that allows you to install and manage many versions. 
  • Pyenv provides many more commands and options for managing Python versions. 
  • Such as uninstalling versions, installing development versions, and setting environment variables. 

tox: 

  • Tox is a command-line tool for automating testing in Python projects. 
  • It allows you to easily run tests across multiple Python environments. 
  • Tox is used in integration pipelines to automate the testing of Python versions. 

pytest: 

  • Pytest is a popular testing framework for Python. 
  • Pytest provides various features for test discovery test execution, fixtures, parameterization, and plugins. 
  • Pytest will run all test functions in the current directory and its subdirectories. 

flake8: 

  • Flake8 is a Python tool that helps enforce code maintainability by checking code. 
  • Flake8 integrates with many popular text editors and integrated development environments (IDEs). 
  • Flake8 as part of the configuring it according to the project's coding standards. 

black: 

  • Black is an opinionated code formatter for Python. 
  • Black will analyze the specified files or directories and automatically format them. 
  • Black integrates with many popular text editors and integrated development environments (IDEs). 

isort: 

  • isort is a Python that helps organize and import statements within Python files. 
  • isort allows customizing its configuration file named. Sort. cfg or pyproject. toml. 
  • isort has no vulnerabilities. It has a Permissive License. 

mypy: 

  • mypy is a Python library used in Code Quality and Code Analyzer applications. 
  • It analyzes Python code and detects type errors. It provides feedback on potential issues before runtime. 
  • Mypy allows one to customize its behavior through a configuration file such as mypy.ini or setup. cfg. 

bandit: 

  • Bandit is a security linter for Python code. It analyzes your code for common security vulnerabilities. 
  • Bandit helps you identify potential security issues early in the development process. 
  • Bandit will analyze the specified directories and report any security issues it finds. 

pre-commit: 

  • Pre-commit is a framework for managing and running pre-commit hooks. 
  • Pre-commit is a Python library used in Code Quality and Code Analyzer applications. 
  • Pre-commit has no bugs. It has no vulnerabilities. 

pip-tools: 

  • Pip-tools are a Python library used in Utilities and Build Tool applications. 
  • Pip-tools are a set of utilities for managing Python dependencies. 
  • It provides tools for generating and updating requirements.txt files. 

FAQ

1. What is Pipenv? 

Pipenv is a tool that combines dependency management. The virtual environment management into a single tool. It simplifies the process of managing dependencies and creating reproducible environments. 


2. What are some essential Pipenv libraries for virtual environment management? 

Pipenv libraries for virtual environment management include pyenv for managing Python versions. The tox for testing automation across many environments. Pip tools for managing dependencies and generating requirements files. 


3. How does pipenv differ from pip? 

Pipenv provides higher-level functionality compared to pip. Pip is a package manager for installing Python packages. Pipenv manages both dependencies and virtual environments, ensuring reproducible development environments. 


4. Why is tox important for reproducible development? 

Tox is essential for reproducible development. It allows you to define and automate testing across multiple Python environments. By running tests in isolated environments with different Python versions and configurations. Tox helps ensure that your code behaves consistently across different environments. 


5. Can I use Flake8 with Pipenv for code linting? 

Yes, Flake8 can be used with Pipenv for code linting. Flake8 is a popular linting tool for Python that checks code against style. It can install Flake8 within your Pipenv virtual environment. It integrates into the development workflow for code quality assurance. 

Syntax highlighting provides the source code's color and style in Visual Studio Code. It improves readability. It also helps programmers find errors in their programs. It has the functionality of auto-language detection and multi-language code highlighting.  

 

Sometimes it is very easy to link with HTML5 tags. You can use attributes and classes for objects icons built on modern web standards. The Rainbow and Prism are the popular syntaxes highlighting libraries. It is very light, fast, and easy to use. Dependencies are free with automatic language detection. You can define it once in one of their common ancestors if many code snippets have the same language. You need to wrap inline code in the HTML tag when using Prism. Depending on the language you are highlighting, apply the appropriate class to it. It supports several languages and has the richest ecosystem of themes and plugins. You can use it to extend its core functionality.  

 

STEPS:  

  • First, include some markup for the code you want to be highlighted. We can define our HTML code language here.  
  • Then include a CSS theme file in the head tag of your page.  
  • Finally, include rainbow js and whatever language(s) you want before the closing body tag.  


Syntax highlighting is a text editor feature. The feature displays text, and source code, in colors and fonts according to the term category. We can use it for programming, scripting, or markup languages like HTML.  

highlight.js:  

  • It works with any markup language.  
  • It is compatible with any js framework.  
  • It is available for node.js.  
  • It has automatic language detection and multi-language code highlighting.  

syntaxhighlighter:  

  • It is a small and self-contained code syntax highlighter.  
  • It helps set the color and style of the source code.  
  • We can also highlight the text.  
  • It improves readability.  

rainbow:  

  • It has a high rich texture.  
  • It is very simple, and light compared to others.  
  • Easy to use and extendable.  
  • It is completely themable through CSS. 

vscode-styled-components:  

  • It has detailed CSS IntelliSense while working in styled strings.  
  • It has Syntax error reporting.  
  • It has components in JavaScript as well as in Typescript.  
  • It has flexibility.  

EnlighterJS:  

  • It is designed to work in all modern browsers.  
  • It has 12 high-quality themes.  
  • Themes are available as single CSS files to reduce footprint.  
  • Minimal, embedded DOM library.  

Primrose:  

  • It has Color theming.  
  • Syntax highlighting for JavaScript, HTML, and BASIC.  
  • It has international keyboard support (left-to-right rendering only).  
  • It has Line numbering availability. 

vscode-lit-html:  

  • It has Formatting support and auto-closing tags.  
  • It works with literal html strings that contain placeholders.  
  • It has CSS completions in style blocks.  
  • It has Quick info hovers on tags.  

Sublime-JS-Custom:  

  • Easy to use.  
  • High performing.  
  • Extensible code editor.  
  • Highly customized. 

FAQ:  

1. What is a JavaScript syntax highlighter, and how does it work?  

Syntax highlighter helps set the color and style of the source code. It is displayed in the Visual Studio Code editor. It highlights keywords, string literals, and other syntactic elements. Syntax highlighting can also draw attention to syntax errors.  

 

2. How can multi-language code highlighting be achieved with a JavaScript library?  

Highlight. js tries to detect the language of a code fragment. It is simple: it highlights a fragment with all the language definitions. It has auto-language detection and multi-language code highlighting.  

 

3. Is there an automatic language detection feature that comes with this library?  

Yes, an automatic language detection feature is coming with this library. For example, in JavaScript, Highlight.js is a syntax highlighter. It works in the browser and the server. It can work with almost any markup. It doesn't depend on other frameworks and has automatic language detection.  

 

4. Are modern web standards supported in this library for syntax highlighting?  

Yes, modern web standards are supported in this library for syntax highlighting. It is built on modern web standards. It is easy to combine with HTML5 tags using attributes and classes for object icons.  

 

5. Which languages are supported by the syntax highlighting library?  

  • apache  
  • C  
  • Java  
  • Javascript  
  • Php  
  • Python  
  • Shell  
  • typescript 

Here's a kit of 8 amazing debugger open-source projects. 

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