@@ -35,7 +35,7 @@ Better not tell you now.
3535Cannot predict now.
3636Concentrate and ask again.
3737
38- ## Very negative
38+ ## Negative
3939Don't count on it.
4040My reply is no.
4141My sources say no.
@@ -45,17 +45,74 @@ Very doubtful.
4545
4646// This should log "The ball has shaken!"
4747// and return the answer.
48- function shakeBall ( ) { }
49-
48+ function shakeBall ( ) {
49+
50+ logged = "The ball has shaken!" ;
51+ answers = [ "Very positive" , "Positive" , "Negative" , "Negative" ]
52+ //
53+ //answers[Math.floor(Math.random()*answers.length)]
54+ //console.log(Math.floor(Math.random()*4));
55+ answer = Math . floor ( Math . random ( ) * answers . length )
56+ return answer . toString ( ) ;
57+ }
58+ //answers[Math.floor(Math.random()*answers.length)]
5059// The answer should come from shaking the ball
51- let answer ;
60+ // let answer;
5261
5362// When checking the answer, we should tell someone if the answer is
5463// - very positive
5564// - positive
5665// - negative
5766// - very negative
58- function checkAnswer ( ) { }
67+ function checkAnswer ( ) {
68+ // console.log("ans from main"+answer);
69+ let subAns ;
70+
71+ //let no=shakeBall();
72+ //console.log("answer again from checkS"+no);
73+ if ( answer == 0 ) {
74+ // ");
75+ subAns = [ "It is certain."
76+ , "It is decidedly so."
77+ , "Without a doubt"
78+ , "Yes - definitely."
79+ , "You may rely on it." ] ;
80+ console . log ( "very positive" ) ;
81+ console . log ( subAns [ Math . floor ( Math . random ( ) * subAns . length ) ] ) ;
82+ return "very positive" ;
83+ }
84+ if ( answer == 1 ) {
85+ subAns = [ "As I see it, yes."
86+ , "Most likely."
87+ , "Outlook good."
88+ , "Yes."
89+ , "Signs point to yes." ] ;
90+ console . log ( "positive" ) ;
91+ console . log ( subAns [ Math . floor ( Math . random ( ) * subAns . length ) ] ) ;
92+ return "positive" ;
93+ }
94+ if ( answer == 2 ) {
95+ subAns = [ "Reply hazy, try again."
96+ , "Ask again later."
97+ , "Better not tell you now."
98+ , "Cannot predict now."
99+ , "Concentrate and ask again." ] ;
100+ console . log ( "negative" ) ;
101+ console . log ( subAns [ Math . floor ( Math . random ( ) * subAns . length ) ] ) ;
102+ return "negative" ;
103+ }
104+ if ( answer == 3 ) {
105+ subAns = [ "Don't count on it."
106+ , "My reply is no."
107+ , "My sources say no."
108+ , "Outlook not so good."
109+ , "Very doubtful." ] ;
110+ console . log ( "very nagative" ) ;
111+ console . log ( subAns [ Math . floor ( Math . random ( ) * subAns . length ) ] ) ;
112+ return "very negative" ;
113+ }
114+
115+ }
59116
60117/* ======= TESTS - DO NOT MODIFY =====
61118There are some Tests in this file that will help you work out if your code is working.
@@ -89,6 +146,7 @@ function testAll() {
89146 `shakeBall logs "The ball has shaken!"` ,
90147 logged === "The ball has shaken!"
91148 ) ;
149+
92150 test ( `shakeBall returns an string answer"` , typeof answer === "string" ) ;
93151 test (
94152 `checkAnswer returns the level of positivity"` ,
0 commit comments