Why my program won’t return a sum in a nested hash?

50 views
0

I am supposed to create a multiple choice test which will return the user’s answer and a grade.

I am having problems when calculating the answers

I have this nested hash in a .txt file. I have used YAML to create and run the test.

---
    1+1?:
      '1': 0
      '2': 1
      '3': 0
    2*2?:
      '2': 0
      '4': 1

And I need the code to calculate a final grade.

The problem is that it calculates all the values in the second hash.

Even if the user answered for example “1+1 = 1”, he will still get one point.

def read_test_from_file
  require 'yaml'
  puts Dir.glob("*.txt")
  puts "Insert subject"

  name_check = gets.chomp

  return YAML::load_file("#{name_check}.txt")
end

def take_test

  puts
  test_to_take = read_test_from_file()
  diff_hash    = Hash.new()

  test_to_take.each do |question, diff_hash|
    puts question

    diff_hash.each do |key, value|
      puts "#{key}"
    end

    diff_hash.each do |key, value|
    end

    solution = gets.chomp
    puts
    if diff_hash.has_key? (solution)
      puts diff_hash [solution]

      puts
    end

    test_to_take

How to Remove all Instances of edit_post_link

FeaturedSolved1.75K viewspagesphptheme twenty elevenpages php theme twenty eleven
0
98
Question is closed for new answers.

Can someone please assist with how to remove from my theme, whilst in author mode, the edit_post_link (Edit link), throughout all my pages. Which php files in the Twenty Eleven theme (WordPress v3.2) do I need to comment out to no longer display this edit link?

I realise that you only see this during author mode but would like to know how to remove altogether.

Thanks.

Question is closed for new answers.
Marked as featured question
View all answers

Just How To Cosplay Superman

25 views.net 2.0cosplay
0

Superman is the character of American DC Comics. It is the first superhero in the history of comics. He debuted in Action Manga(June 1938), often wearing blue costumes, red cloaks and red and yellow shields, which is the logo of S. He has the power of steel and is endless. Superman was born in the comet and was sent to the Earth by his parents when the comet was nearing destruction. He was picked up by the farmer’s couple and raised in the name of Clark Kent. When he grew up, Clark became a journalist. In the moment of human crisis, he became an incarnation of Superman and walked out to save the world.
For cosplay lovers who love Superman, it is very simple to imitate Superman. Let’s take a look at what cosplaying Superman needs to prepare.
Clothes:
As mentioned above, Superman wearing blue costumes. The whole piece is made of pearl skin and is very smooth. On both sides of the waist and on the wrist, there are lots of stripes to decorate this cloth. The waist of the clothes has a yellow stripe just like a belt that surrounds the entire waist. The zipper of the clothes is on the back, and when you put on the cloak, the zipper will be covered.
The logo with the S is printed on the chest. This sign looks like a shield from the shape, the shield is red,and the logo of S is yellow. This sign makes the person wearing the clothes more like Superman, and feeling that he is full of strength. The jumpsuit is also blue, you will be more handsome after wearing it.
Cloak:
The cloak is an indispensable part of Superman. You have a cloak so that you can play Superman perfectly. The cloak is made of red wool and the top of this cape is attached to the garment, making the cloak fit the shoulders. This cloak is long and the tail is straight to the ankle.
Boots:
Superman has a pair of red boots, and boots are standard for every superhero. The shoes are very comfortable, and the red shoes look very nice with the blue clothes. The top of shoes are designed with a small opening to make it easier for people to wear these shoes.
The above is the costume of Superman. With these pieces of equipment, you can protect the world like Superman. You can wear it to various shows, or you can take very handsome photos. Come to qualitycosplay.com and you will find all of things which you want.

Changed status to publish
View all answers

Unable to get new values from external module

0

I have a date module that returns current date that is set in system:

function getDateFormatAndISODate() {
    const dates = require('./resources/getSystemDate').getSystemDate();
    return dates;
}
module.exports.getDateFormatAndISODate = getDateFormatAndISODate;

I am requiring it in another file:

import * as isoDateModule from './datastream-get-iso-module';

The issue is the method call is not returning new date values when user changes the date manually from system and call this method again:

isoDateModule.getDateFormatAndISODate(dateVal);

I am using c node addon in my project and I am requiring it like this:

function requireUncached(module) {
    delete require.cache[require.resolve(module)];
    return require(module);
}

const dates = requireUncached('./resources/getSystemDate').getSystemDate();

But I am getting error:

EPERM: operation not permitted, unlink 'D:e5datastreambuildsrcdata-retrievalresourcesgetSystemDate.node'
    at Object.unlinkSync (fs.js:956:3)
View all answers

Axios post request with with credentials and body

12 viewsaxioscurlnode.jsaxios curl node.js
0

I am trying to make the same request below in Axios, but it seems to not work. Does anyone have any idea?

curl -X POST -vu CLIENT_ID:CLIENT_SECRET http://localhost:9001/oauth/token -d "grant_type=password&username=user&password=password"

in Axios:

var reqData = "grant_type=password&username=username&password=password"

return axios.post("http://localhost:9001/oauth/token", reqData , {
      headers: {
        "Postman-Token": "4b7526c0-a204-4ad5-6194-49e0cd1bfd12",
        "Cache-Control": "no-cache",
        "Authorization": "Basic "+base64.encode(CLIENT_ID + ':' + CLIENT_SECRET),
        "Content-Type": "application/x-www-form-urlencoded"
      }
    }).then(response => {
      console.log(response)
    return response})

View all answers

Push Notifications For An OTP Mobile Application

0

I was given the following challenge: “I want you to develop a mobile application based on react native. It’s an authentication app. Which means I want to open a website and try to login and when I do. I will receive a push notification on the device when I open it I will get a code to enter on the website when I do I should be logged in”.

I didn’t start with the code yet, I’m trying to figure out how the process will be done.
I was thinking of implementing a TOTP algorithm using Node.JS, but then I got stuck on how the app will know that we logged in on a website and send a push notification.

View all answers
= diff_hash diff_hash["Answer"] = solution total_score += diff_hash[solution] #this is inside the loop as you said end total_score = 0 # and this one outside the loop puts total_score endputs take_test

Can someone help me? Please.